C # 3.0 Value of expression () =>
This is a lambda expression . The code in your example is equivalent to this:
return new MyItem(itemId, delegate() { MyFunction(myParam); });
Here are simple examples of the lambda that I just created:
internal class Program
{
private static void Main(string[] args)
{
var item = new MyItem("Test");
Console.WriteLine(item.Text);
item.ChangeText(arg => MyFunc(item.Text));
Console.WriteLine(item.Text);
}
private static string MyFunc(string text)
{
return text.ToUpper();
}
}
internal class MyItem
{
public string Text { get; private set; }
public MyItem(string text)
{
Text = text;
}
public void ChangeText(Func<string, string> func)
{
Text = func(Text);
}
}
The output will be:
Test
TEST