Random r = new Random();
List<object> myList = new List<object>();
for (int i = 0; i < 100; i++)
myList.Add(new { A = r.Next(), B = r.Next() });
myList.Sort( (obj1, obj2) => obj1.A.CompareTo(obj2.A) );
The code above defines a generic code Listthat fills it with 100 anonymous variables with two members, A and B.
Let's say I want to sort myList by A. The last line tries to sort the list, however this code does not explicitly compile because the compiler does not know what the list of objects contains.
Without using LINQ, is there any way to sort this list using lambdas or the like?
source
share