Ever wondered how to print the text in a sentence in reverse? Well here is a C# solution that I came up with after reading chapter 9 of Jesse Liberty’s Programming C# 3.0. The array object has a method that can reverse the content of the array. Yeah as simple as that. So basically what you do is read the text into an array and reverse the array.
namespace ReverseText
{
class MyReverseText
{
static void Main(string[] args)
{
string myText = "This is my sentence";
string[] arrayNo = new string[myText.Length];
for (int i = 0; i < myText.Length; i++)
{
arrayNo[i] = myText.Substring(i, 1);
}
Array.Reverse(arrayNo);
PrintMyArray(arrayNo);
}
public static void PrintMyArray(object[] theArray)
{
foreach(object obj in theArray)
{
Console.Write("{0}", obj);
};
Console.WriteLine("\n");
}
}
}