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 个输入参数传递给委托(delegate) Action?
最佳答案
使用 Action<string, string, string>
而不是 Action
.
记住 - 有一组 Action
代表们。所有这些委托(delegate)都封装了不返回值的方法(即具有 void
返回类型)。但是 void 方法有不同数量的输入参数。因此有 17 个不同的 Action
委托(delegate),它封装了具有不同数量输入参数(从 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>
所以,你应该选择合适的代表
关于c# - 委托(delegate)操作不接受 3 个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23605507/