Tuesday, June 17, 2008 3:01 PM
hoonius
I ♥ List<>
Anyone like List<>?
Since I've been writing LINQ in my apps, i've got right into using them wherever possible. You can fill them up with your custom objects, select, sort, the lot
public class TimzObject
{
private string _Name;
private int _Age;
public string Name
{
get
{
return _Name;
}
}
public int Age
{
get
{
return _Age;
}
}
public TimzObject(string strName, int nAge)
{
this._Name = strName;
this._Age = nAge;
}
public TimzObject()
{
}
}
Then make your List<>
List myList = new List<TimzObject>();
myList.Add(new TimzObject("Tim Hustler", 30)); //my real age
myList.Add(new TimzObject("Angelina Jolie", 21)); // her 'real' age (she wishes)
//sort by Age
myList.Sort(
delegate(TimzObject A, TimzObject B)
{
return A.Age.CompareTo(B.Age);
});
I'll extend this as time allows :¬)
Filed under: IEnumerable, List<>, LINQ, C#