Reputation: 14155
I'm trying to reverse string elements inside array, but I'm getting exact string order. Here's the code
public static void ReverseArrayElements()
{
Console.WriteLine("This will init array elements and reverse its elements");
string[] elements = { "one, two, three" };
for (int i = 0; i < elements.Length; i++)
{
Console.WriteLine("Array elements before reversing: {0}", elements[i]);
}
Console.WriteLine("\n");
Array.Reverse(elements);
for (int i = 0; i < elements.Length; i++)
{
Console.WriteLine("Array elements after reversing: {0}", elements[i]);
}
Console.ReadLine();
}
Result is one, two, three and after sorting again one, two, three.
What am I doing wrong here?
Upvotes: 1
Views: 5847
Reputation: 11860
You've created an array of one element, containing the string "one, two, three".
Instead, you want to intialise that array with:
string[] elements = { "one", "two", "three" };
Upvotes: 9