我想知道是否有可能(以及什麼語法)將對象的方法發送到函數。是否可以將對象的方法發送給函數?
例子:
Object "myObject" has two methods "method1" and "method2"
我想有沿線的一個功能:
public bool myFunc(var methodOnObject)
{
[code here]
var returnVal = [run methodOnObject here]
[code here]
return returnVal;
}
因此,在其他功能我可以做類似
public void overallFunction()
{
var myObject = new ObjectItem();
var method1Success = myFunc(myObject.method1);
var method2Success = myFunc(myObject.method2);
}
Delgates應該解決您的問題 – 2009-08-25 13:48:35