Blog

Declare String in c#

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

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs