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);
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
More Blogs from this Blogger
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts