Action(T) Generic Delegate

Posted by Tim on January 19, 2009 in C# |

Very useful delegate to create anonymous functions…why? This is especially useful when you have repeated code within a function.

This particular example gets a list of tables from a database based on a key that is consumed by the id parameter.

The Action(T) delegate can have zero to several different parameter types.

Action getTables(String id) = delegate() {
List<Tables> lTables = new Select().From<Tables>.Where<Tables.RelatedId>().IsEqualTo(id).ExecuteTypedList<Tables>();
});

Call the function within the function you declared the anonymous function:

getTables(“1”);

That simple…Awesome!

References:

http://msdn.microsoft.com/en-us/library/018hxwa8.aspx

Tags: ,

Leave a Reply

Copyright © 2008-2012 Codelab Blog All rights reserved.
Desk Mess Mirrored version 1.9.1 theme from BuyNowShop.com.