You could optionally resort the string in the reverse order and then run your
foreach loop as usual. eg.
class ReversedComparer:IComparer
{
public int Compare(object x,object y)
{
if((char)x < (char)y)
return 1;
else if((char)x > (char)y)
return -1;
else
return 0;
}
}
Array array = s.ToCharArray();
Array.Sort(array,new ReversedComparer());
//s = new String((char[])array);
foreach(char c in array)
{
Console.WriteLine(c);
}
"Elementary Penguin" wrote:
is there a way to decrement a foreach loop?
for example
string s = "cat";
foreach(char c in s)
//some how it goes backward here
Console.WriteLine(c);
and so the result would be
t
a
c
--
Texeme
http://texeme.com