Posts

Showing posts with the label Lambda Expression

Callbacks And Delegates

It's been a couple of weeks since last writing. Besides being very busy, I've had a touch of "writer's block". Nothing too serious, I should get over it soon. Lately, I've been intrigued by the abundant use of callback functions and delegates in the .NET Framework. If you want to do anything interesting, you gotta know callbacks. I'll try to describe callbacks and delegates in simplistic terms. Maybe it will help you over the hump. Consider the following code... List list = new List (); //Populate list with some MyClass objects for(int i=0; i list.Add(new MyClass(){ ID=i, strValue=i.ToString() }); //Sort the list list.Sort(); foreach(MyClass c in list) Console.WriteLine("{0}",c.strValue); ... public class MyClass { public int ID; public string strValue; public override string ToString() { return strValue; } } This code throws an exception at the line that says S...