variation in programming
Hello,
Im just working my way through the book and just doing the excersizes in chapter 5. This is what i wrote for Q5 before I looked at the answer given
Console.WriteLine("Please enter a string to be written backwards:");
string myString=Console.ReadLine();
char[] myChar = myString.ToCharArray();
for (int i=1;i<= myString.Length;i++)
{
Console.Write(myChar[myString.Length-i]);
}
Console.Write("\n");
The answer given,
Console.WriteLine("Enter a string:");
string myString = Console.ReadLine();
string reversedString = "";
for (int index = myString.Length - 1; index >= 0; index--)
{
reversedString += myString[index];
}
Console.WriteLine("Reversed: {0}", reversedString);
My question is, Is my answer fine as it does the same thing, and what are the advantages/disadvantages of writing the way its given in the textbook answer. Overheads?
Any reply ould be greatly appreciated
|