C# 在实体构造上使用lamda表达式的代码是如何工作的

C# 在实体构造上使用lamda表达式的代码是如何工作的,c#,C#,以下代码的含义是什么 var personDataTemplate = new DataTemplate(() => { var grid = new Grid(); ... var nameLabel = new Label { FontAttributes = FontAttributes.Bold }; var ageLabel = new Label(); var locationLabel =

以下代码的含义是什么

var personDataTemplate = new DataTemplate(() =>
    {
        var grid = new Grid();
        ...
        var nameLabel = new Label { FontAttributes = FontAttributes.Bold };
        var ageLabel = new Label();
        var locationLabel = new Label { HorizontalTextAlignment = TextAlignment.End };

        nameLabel.SetBinding(Label.TextProperty, "Name");
        ageLabel.SetBinding(Label.TextProperty, "Age");
        locationLabel.SetBinding(Label.TextProperty, "Location");

        grid.Children.Add(nameLabel);
        grid.Children.Add(ageLabel, 1, 0);
        grid.Children.Add(locationLabel, 2, 0);

        return new ViewCell { View = grid };
    });
代码如何与以下实例一起运行

new DataTemplate(() => { --- How the code runs here --- })

它像一个自调用函数吗?

DataTemplate的构造函数有一个接受委托的参数,可能类似于

public DataTemplate(Func<ViewCell> foo)

您可以使用它来允许用户定义自己应该在内部使用的
ViewCell
实例。

DataTemplate的构造函数有一个接受委托的参数,可能类似于

public DataTemplate(Func<ViewCell> foo)

您可以使用它来允许用户定义自己的
ViewCell
实例,该实例应在内部使用。

感谢您的回复。所以,如果我需要向匿名方法发送参数,我是否会像(param)=>{}那样发送它?@AryanM是的。例如
Func-foo
可以作为
myInt=>{return(double)myInt;}
调用。如果您不需要任何返回类型,可以使用
Action
而不是
Func
。感谢您的回复。所以,如果我需要向匿名方法发送参数,我是否会像(param)=>{}那样发送它?@AryanM是的。例如
Func-foo
可以作为
myInt=>{return(double)myInt;}
调用。如果不需要任何返回类型,可以使用
Action
而不是
Func