Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with new Action(() => someCombobox.Text = "x" )

Tags:

c#

lambda

When I write in my code

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

I get this error:

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

Why?

This question is related to this one. I just want to understand why this error occurs.

like image 490
Bastien Vandamme Avatar asked Dec 12 '22 05:12

Bastien Vandamme


1 Answers

You do not have to pass that as a constructor parameter:

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

All you have to do is to declare an action and then use lambda expression to create it.

Alternatively you can pass the string to the action:

  Action<string> a = (s) => someCombobox.Text = s;
  a("your string here");
like image 96
Aliostad Avatar answered Jan 05 '23 10:01

Aliostad