foreach (string s in list)
{
Console.WriteLi ne(s);
}
The alternative would be to write a class that implements
IComparer<strin g- but the above is a lot easier ;-p
For reference, 3.5 (and LINQ) has a lot of support for ordering based
on projections (such as s =s.Length) - but if you have a C# 3
compiler you can still use this with .NET 2.0 via LINQBridge - then it
is as simple as:
foreach (string s in list.OrderBy(s= >s.Length))
{
Console.WriteLi ne(s);
}
Comment