以下是我在C#代碼...回調
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
TestPointer test = new TestPointer();
test.function1(function2); // Error here: The name 'function2' does not exist in current context
}
}
class TestPointer
{
private delegate void fPointer(); // point to every functions that it has void as return value and with no input parameter
public void function1(fPointer ftr)
{
fPointer point = new fPointer(ftr);
point();
}
public void function2()
{
Console.WriteLine("Bla");
}
}
我如何通過傳遞函數refernce在主函數中調用回調函數?... 我是新來的C#
你到底想達到什麼目的? (順便說一句,這看起來像_C#_,而不是C++)。 – Oded