C# 如何将值从匿名方法返回到标签?
我想了解匿名方法的工作原理,并在标签(Windows窗体)中显示结果: 但这不是工作。它是如何修复的?试试这个: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
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更新为一行