-1
我正在尋找使用函數委託調用具有參數的方法的方法。具有參數的函數代表c#
您可以使用函數delegate而不是調用processOperationB。但尋找可以實現以下方法的任何方式。
public class Client
{
public AOutput OperationA (string param1, string param2)
{
//Some Operation
}
public BOutput OperationB(string param1, string param2)
{
//Some Operation
}
}
public class Manager
{
private Client cl;
public Manager()
{
cl=new Client();
}
private void processOperationA(string param1, string param2)
{
var res = cl.OperationA(param1,param2);
//...
}
private void processOperationB(string param1, string param2)
{
var res = cl.OperationB(param1,param2);
// trying to Call using the GetData , in that case I could get rid of individual menthods for processOperationA, processOperationB
var res= GetData<BOutput>(x=> x.OperationB(param1,param2));
}
// It could have been done using Action, but it should return a value
private T GetData<T>(Func<Client,T> delegateMethod)
{
// how a Function delegate with params can be invoked
// Compiler expects the arguments to be passed here. But have already passed all params .
delegateMethod();
}
}
好的,那個代碼有什麼問題?你有錯誤嗎?什麼錯誤? – JLRishe
目前還不清楚你在做什麼......爲什麼會調用'GetData'的目的是直接執行代碼...... – Phil1970