.NET FAQs Unleashed!
 
    
    

How can you initialize a string from a char[]?

Say you want to initialize a string called str and set its value to “Drink beer”.

Here is how you would do it using char literals:

String str = new string(new [] {‘D’,’r’,’i’,’n’,’k’,’ ‘,’b’,’e’,’e’,’r’});

Definition   Display 5555 as 0005555   Initialize string from a char[]   Format decimal as currency   Output int type as hexadecimal string   Display a number in exponential   Display a number as a percent   Is String a reference type   ToString("F2")    @ before double quotes   Carriage return   Escape Sequence Why do we use backslash characters with strings?   String VS. string   \u0042\u0041\u0044  

More Interview Questions.....