Code
// Declare without initializing.Code
string message1;
// Initialize to null.Code
string message2 = null// Initialize as an empty string.Code
Code
// Use the Empty constant instead of the literal "".Code
string message3 = System.String.Empty;Code
// Use System.String if you prefer.Code
System.String greeting = "Hello World!";Code
// Use a const string to prevent 'message4' fromCode
// being used to store another string value.Code
const string message4 = "You can't get rid of me!";Code
// Use the String constructor only when creatingCode
// a string from a char*, char[], or sbyte*.Code
// System.String documentation for details.Code
char[] letters = { 'A', 'B', 'C' };Code
string alphabet = new string(letters);
Join the conversation! Your thoughts help the community grow.