As others have said, this is a lambda, which is basically an anonymous (unnamed) local function.
This might make a little more difference if you look at some similar code that doesn't use lambdas:
// With a lambda private void OnFormLoad() { ThreadPool.QueueUserWorkItem(() => GetSqlData()); } // Without a lambda private void OnFormLoad() { ThreadPool.QueueUserWorkItem(ExecuteGetSqlData); } private void ExecuteGetSqlData() { // If GetSqlData returns something, change this to "return GetSqlData();" GetSqlData(); }
As with other code, usually you do not need to do a new Action . The problem is that the BeginInvoke method accepts a Delegate , which is a kind of old school, and breaks how most new codes work.
With newer code (which accepts something like Action or a specific type of delegate, such as WaitCallback ), you either write a lambda, or simply specify the name of the function inside your class. The code sample I wrote above demonstrates both of these options.
Also note that if you see something like: (Action) (() => Blah()) , this is almost the same as new Action(() => Blah()) .
Merlyn morgan-graham
source share