Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将值从匿名方法返回到标签?_C#_Winforms - Fatal编程技术网

C# 如何将值从匿名方法返回到标签?

C# 如何将值从匿名方法返回到标签?,c#,winforms,C#,Winforms,我想了解匿名方法的工作原理,并在标签(Windows窗体)中显示结果: 但这不是工作。它是如何修复的?试试这个: label1.Text = new Func<string>(() => { return "Some text"; })(); label1.Text=newfunc(()=>{return“Some Text”;})(); 试试这个: label1.Text = new Func<string>(() => { return "Some te

我想了解匿名方法的工作原理,并在标签(Windows窗体)中显示结果:

但这不是工作。它是如何修复的?

试试这个:

label1.Text = new Func<string>(() => { return "Some text"; })();
label1.Text=newfunc(()=>{return“Some Text”;})();
试试这个:

label1.Text = new Func<string>(() => { return "Some text"; })();
label1.Text=newfunc(()=>{return“Some Text”;})();
试试这个

Func<string> func = () =>
{
    return "Some text";
};

label1.Text= func();
Func-Func=()=>
{
返回“一些文本”;
};
label1.Text=func();
一行

label1.Text= new Func<string>(() => "Some text")();
label1.Text=newfunc(()=>“一些文本”)();
试试这个

Func<string> func = () =>
{
    return "Some text";
};

label1.Text= func();
Func-Func=()=>
{
返回“一些文本”;
};
label1.Text=func();
一行

label1.Text= new Func<string>(() => "Some text")();
label1.Text=newfunc(()=>“一些文本”)();

文本
是一个
字符串
,而不是
函数
。这有什么用?为什么需要一行代码?我需要在一个项目中使用非常小的代码。
文本是
字符串,而不是
函数。这有什么用?为什么需要一行代码?我需要在一个项目中使用非常小的代码。这就是我需要的。谢谢这就是我需要的。谢谢@泰坦一号更新line@titans更新为一行