C# function pointer?

前端 未结 5 1980
情话喂你
情话喂你 2020-12-25 12:40

I\'m having a problem with C#, I\'d like to get a pointer of a method in my code, but it seems impossible. I need the pointer of the method because I want to no-op it using

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 13:10

    I'd wish it is useful

    class Program
    {
    
        static void Main(string[] args)
        {
            TestPointer test = new TestPointer();
            test.function1();
        }
    }
    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 point = new fPointer(function2);
            point();
        }
        private void function2()
        {
            Console.WriteLine("Bla");
        }
    }
    

提交回复
热议问题