Blog

Declare String in c#

Posted by Mohammad Sufiyan Shaikh Blogs | C# Language Nov 11, 2012
You can declare and initialize strings in various ways, as shown in the following example
// 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);
COMMENT USING
PREMIUM SPONSORS
More Blogs from this Blogger
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.