Calling a function from a string in C#

前端 未结 6 1583
别那么骄傲
别那么骄傲 2020-11-22 11:41

I know in php you are able to make a call like:

$function_name = \'hello\';
$function_name();

function hello() { echo \'hello\'; }

Is this

6条回答
  •  轮回少年
    2020-11-22 12:38

    In C#, you can create delegates as function pointers. Check out the following MSDN article for information on usage: http://msdn.microsoft.com/en-us/library/ms173171(VS.80).aspx

        public static void hello()
        {
            Console.Write("hello world");
        }
    
       /* code snipped */
    
        public delegate void functionPointer();
    
        functionPointer foo = hello;
        foo();  // Writes hello world to the console.
    

提交回复
热议问题