Rewriting VB.NET Lambda experession as a C# statement

Posted by ChadD on Stack Overflow See other posts from Stack Overflow or by ChadD
Published on 2012-08-31T03:34:33Z Indexed on 2012/08/31 3:38 UTC
Read the original article Hit count: 407

Filed under:
|
|

I downgraded my app from version 4 of the framework to version 4 and now I want to implement this VB.NET lambda function statement (which works on 3.5)

Dim colLambda As ColumnItemValueAccessor = Function(rowItem As Object) General_ItemValueAccessor(rowItem, colName)

and rewrite it in C#. This was my attempt:

ColumnItemValueAccessor colLambda = (object rowItem) => General_ItemValueAccessor(rowItem, colName);

When I did this, I get the following error:

Error   14  One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll? C:\Source\DotNet\SqlSmoke\SqlSmoke\UserControls\ScriptUserControl.cs    84  73  SqlSmoke

However, when I downgraded the app from version 4.0 of the framework to 3.5 (because our users only hae 3.5 and don't have rights to install 4.0). when I did this, the reference to "Microsoft.CSharp" was broken.

Can I rewrite the VB.NET command in C# using syntax that is valid in C# 3.5 as I was able to in VB.NET? What would the syntax be?

© Stack Overflow or respective owner

Related posts about c#

Related posts about vb.net