2
Action showTasks = (String name, String gender, String id) =>
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("Name: " + name);
            stringBuilder.Append(System.Environment.NewLine);
            stringBuilder.Append("Gender: " + gender);
            stringBuilder.Append(System.Environment.NewLine);
            stringBuilder.Append("Id: " + id);

            var builderGoogle = new AlertDialog.Builder (this);
            builderGoogle.SetTitle ("Logged in");
            builderGoogle.SetMessage (stringBuilder.ToString());
            builderGoogle.SetPositiveButton ("Ok", (o, e) => { });
            builderGoogle.Create().Show();
        };

How can I pass 3 input parameters to delegate Action?

senzacionale
  • 20,448
  • 67
  • 204
  • 316

3 Answers3

7

Use Action<string, string, string> instead of Action.

Remember - there is set of Action delegates. All these delegates encapsulate methods which don't return value (i.e. have void return type). But void methods have different number of input parameters. Thus there is 17 different Action delegates, which encapsulate methods with different number of input parameters (from 0 to 16);

Action
Action<T1>
Action<T1,T2>
Action<T1,T2,T3>
...
Action<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>

So, you should pick appropriate delegate

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
5

Use the Action<T1, T2, T3> delegate:

Action<String, String, String> showTasks = (String name, String gender, String id) =>
Hamlet Hakobyan
  • 32,965
  • 6
  • 52
  • 68
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
3

Change your type:

Action<string, string, string> showTasks = ...
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321