Say I have an array of string
s like this:
string [] foos = {
"abc",
"def",
"ghi"
};
I want a new collection that contains each string and its reverse. So the result should be:
"abc",
"cba",
"def",
"fed",
"ghi",
"ihg"
I could just iterate through the array, but this is pretty clumsy:
string Reverse (string str)
{
return new string (str.Reverse ().ToArray ());
}
List<string> results = new List<string> ();
foreach (string foo in foos) {
results.Add (foo);
results.Add (Reverse(str));
}
Is there a way to do this in LINQ? Something like
var results = from foo in foos
select foo /* and also */ select Reverse(foo)