With generic in C# 2.0 life just become so much easier. Today I was impressed by the ease with which you can now sort a list of T.
Code below shows how with one method you can now implement a sort. This used to be much more complex!
public class Person { public Person(string name) { this.Name = name; } public string Name; } class Demo { public List GetAllPersons() { List result = new List(); result.Add(new Person("Mark")); result.Add(new Person("Dennis")); result.Add(new Person("Duncan")); result.Add(new Person("Jeremy")); result.Sort(SortByName); return result; } public static int SortByName( Person x, Person y ) { return x.Name.CompareTo(y.Name); } }
dasBlog theme by Mads Kristensen
Concepts LINQ Entity Framework WCF WPF RESTful Web Unit Testing .NET Workflow More >>
Tools Visual Studio Windows IIS Silverlight More >>
Type Screencast Tools Video Newsletter Sample Article Books Magazine How To Demo Course Products More >>