Friday, April 10, 2009

How to reverse string

   26             string originalString = "123456789";

   27             char[] buffer = originalString.ToCharArray();

   28             Array.Reverse(buffer);

   29             string reversedString = new String(buffer);

   30 

   31             Console.WriteLine();

   32             Console.WriteLine("original string: " + originalString);

   33             Console.WriteLine("reversed string: " + reversedString);

 

image

How to fill String variable.

To fill a string variable, sometimes, they use next way:       const string breakLine = "----------";

Seems, next way (usage one of string’s constructor) will be better:

string line = new string('-', 10);
Console.WriteLine("new string('-', 10) >" + line);

 

Console Output:

image