Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何调用Func<;int,int,int>;C#中方法中的参数?_C#_Func_Actionmethod - Fatal编程技术网

如何调用Func<;int,int,int>;C#中方法中的参数?

如何调用Func<;int,int,int>;C#中方法中的参数?,c#,func,actionmethod,C#,Func,Actionmethod,我正在尝试创建一个接受不同方法(Funcs)作为参数的方法。 我在定义Funcs参数时遇到了一个小问题。 假设我需要调用这样的东西: public static void SomeTestMethod(int number,string str) { Check(MethodOne(number,str)); } 我这里有一个: public static int Check(Func<int,string,int> method) { // some c

我正在尝试创建一个接受不同方法(
Func
s)作为参数的方法。
我在定义
Func
s参数时遇到了一个小问题。 假设我需要调用这样的东西:

public static void SomeTestMethod(int number,string str)
{
    Check(MethodOne(number,str));
}
我这里有一个:

public static int Check(Func<int,string,int> method)
{
         // some conditions 
      method(where should i get the arguments ?);
}
如果可能,我需要提供此签名:

Check(MethodOne(number,str));
您缺少返回值的类型(最后一个泛型参数表示返回值的类型)。如果您不想
Func
返回任何内容,只需使用
Action

public static void Check(
                       Action<int, string> method, 
                       int arg1, 
                       string arg2)
{
    method(arg1, arg2);
}
公共静态无效检查(
行动方法,
int arg1,
字符串arg2)
{
方法(arg1,arg2);
}
您缺少返回值的类型(最后一个泛型参数表示返回值的类型)。如果您不想
Func
返回任何内容,只需使用
Action

public static void Check(
                       Action<int, string> method, 
                       int arg1, 
                       string arg2)
{
    method(arg1, arg2);
}
公共静态无效检查(
行动方法,
int arg1,
字符串arg2)
{
方法(arg1,arg2);
}
您缺少返回值的类型(最后一个泛型参数表示返回值的类型)。如果您不想
Func
返回任何内容,只需使用
Action

public static void Check(
                       Action<int, string> method, 
                       int arg1, 
                       string arg2)
{
    method(arg1, arg2);
}
公共静态无效检查(
行动方法,
int arg1,
字符串arg2)
{
方法(arg1,arg2);
}
您缺少返回值的类型(最后一个泛型参数表示返回值的类型)。如果您不想
Func
返回任何内容,只需使用
Action

public static void Check(
                       Action<int, string> method, 
                       int arg1, 
                       string arg2)
{
    method(arg1, arg2);
}
公共静态无效检查(
行动方法,
int arg1,
字符串arg2)
{
方法(arg1,arg2);
}
我想你想要这个:

public static void SomeTestMethod(int number,string str)
{
    Check( () => MethodOne(number,str));
}

public static int Check(Func<int> method)
{
         // some conditions 
      return method();
}
publicstaticvoidsometestmethod(int-number,stringstr)
{
检查(()=>MethodOne(编号,str));
}
公共静态整型检查(Func方法)
{
//一些条件
返回方法();
}
我想你想要这个:

public static void SomeTestMethod(int number,string str)
{
    Check( () => MethodOne(number,str));
}

public static int Check(Func<int> method)
{
         // some conditions 
      return method();
}
publicstaticvoidsometestmethod(int-number,stringstr)
{
检查(()=>MethodOne(编号,str));
}
公共静态整型检查(Func方法)
{
//一些条件
返回方法();
}
我想你想要这个:

public static void SomeTestMethod(int number,string str)
{
    Check( () => MethodOne(number,str));
}

public static int Check(Func<int> method)
{
         // some conditions 
      return method();
}
publicstaticvoidsometestmethod(int-number,stringstr)
{
检查(()=>MethodOne(编号,str));
}
公共静态整型检查(Func方法)
{
//一些条件
返回方法();
}
我想你想要这个:

public static void SomeTestMethod(int number,string str)
{
    Check( () => MethodOne(number,str));
}

public static int Check(Func<int> method)
{
         // some conditions 
      return method();
}
publicstaticvoidsometestmethod(int-number,stringstr)
{
检查(()=>MethodOne(编号,str));
}
公共静态整型检查(Func方法)
{
//一些条件
返回方法();
}

不清楚您在问什么。如果编译成功,则
MethodOne
返回
Func
。如果你能提供一个简短但完整的程序来演示这个问题,并解释你想要实现的目标,那将非常有帮助。我们应该如何知道呢?请注意,
Func
只接受一个参数(一个int)并返回一个
字符串。您可以像这样调用它
var result=method(someInt)-大概是
检查
然后应该对
结果
进行推理,还是返回它?我编辑了这个问题@JonSkeet@StuartLC当前位置错过了,更正了问题。不清楚你在问什么。如果编译成功,则
MethodOne
返回
Func
。如果你能提供一个简短但完整的程序来演示这个问题,并解释你想要实现的目标,那将非常有帮助。我们应该如何知道呢?请注意,
Func
只接受一个参数(一个int)并返回一个
字符串。您可以像这样调用它
var result=method(someInt)-大概是
检查
然后应该对
结果
进行推理,还是返回它?我编辑了这个问题@JonSkeet@StuartLC当前位置错过了,更正了问题。不清楚你在问什么。如果编译成功,则
MethodOne
返回
Func
。如果你能提供一个简短但完整的程序来演示这个问题,并解释你想要实现的目标,那将非常有帮助。我们应该如何知道呢?请注意,
Func
只接受一个参数(一个int)并返回一个
字符串。您可以像这样调用它
var result=method(someInt)-大概是
检查
然后应该对
结果
进行推理,还是返回它?我编辑了这个问题@JonSkeet@StuartLC当前位置错过了,更正了问题。不清楚你在问什么。如果编译成功,则
MethodOne
返回
Func
。如果你能提供一个简短但完整的程序来演示这个问题,并解释你想要实现的目标,那将非常有帮助。我们应该如何知道呢?请注意,
Func
只接受一个参数(一个int)并返回一个
字符串。您可以像这样调用它
var result=method(someInt)-大概是
检查
然后应该对
结果
进行推理,还是返回它?我编辑了这个问题@JonSkeet@StuartLC:错过了,更正了问题。谢谢,我完全忘记了lambdas:),谢谢,我完全忘记了lambdas:),谢谢,我完全忘记了lambdas:),谢谢,我完全忘了兰博达斯:),谢谢