Declare String in c#

By Mohammad Sufiyan Shaikh Nov 11 2012
You can declare and initialize strings in various ways, as shown in the following example
    • Like
    • Love It
    • Awesome
    • Interesting
    • It's Okay
    • Thumbs Down
  • 5k
  • 0
// Declare without initializing. 
 string message1;
// Initialize to null. 
 string message2 = null// Initialize as an empty string. 

// Use the Empty constant instead of the literal "".
 string message3 = System.String.Empty;
 // Use System.String if you prefer.
System.String greeting = "Hello World!";
 // Use a const string to prevent 'message4' from 
 // being used to store another string value. 
 const string message4 = "You can't get rid of me!";
 // Use the String constructor only when creating 
 // a string from a char*, char[], or sbyte*. 
 // System.String documentation for details. 
 char[] letters = { 'A', 'B', 'C' };
 string alphabet = new string(letters);