Delegate Action不带3个参数

本文关键字:参数 3个 不带 Action Delegate | 更新日期: 2023-09-27 18:02:57

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();
        };

如何传递3个输入参数来委派Action?

Delegate Action不带3个参数

Action<string, string, string>代替Action

记住-有一组Action委托。所有这些委托封装了不返回值的方法(即具有void返回类型)。但是void方法有不同数量的输入参数。因此,有17个不同的Action委托,它们封装了具有不同数量输入参数的方法(从0到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>
所以你应该选择合适的委托

使用Action<T1, T2, T3>委托:

Action<String, String, String> showTasks = (String name, String gender, String id) =>

修改字体:

Action<string, string, string> showTasks = ...