someCombobox.Text = "x" ) 我收到这个错误: Delegate 'System.Action' does not take 0 ar-6ren">
gpt4 book ai didi

c# - new Action(() => someCombobox.Text = "x"有什么问题)

转载 作者:太空狗 更新时间:2023-10-30 00:08:23 26 4
gpt4 key购买 nike

当我写代码的时候

Action(() => someCombobox.Text = "x" )

我收到这个错误:

Delegate 'System.Action<object>' does not take 0 arguments

为什么?

这个问题与this one有关.我只是想了解为什么会出现此错误。

最佳答案

您不必将其作为构造函数参数传递:

 Action a = () => someCombobox.Text = "x";

您所要做的就是声明一个 Action ,然后使用 lambda 表达式来创建它。

或者,您可以将字符串传递给操作:

  Action<string> a = (s) => someCombobox.Text = s;
a("your string here");

关于c# - new Action(() => someCombobox.Text = "x"有什么问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9002593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com