精易论坛

标题: 委托使用? [打印本页]

作者: shunjie    时间: 2016-5-5 13:42
标题: 委托使用?
一个c++写的dll,用到一个函数 的参数里是子程序子针, c#这里该怎么填?听说用委托,尝试了下,但不怎么会使用,能不能举个简单例子……

作者: 古龙若风    时间: 2016-5-6 06:56
用不安全代码,亲
作者: shunjie    时间: 2016-5-6 20:26
古龙若风 发表于 2016-5-6 06:56
用不安全代码,亲

能否举个简单例子? unsafe{}会取变量地址,方法的指针咋取呢?
作者: web11234    时间: 2016-5-7 08:24
shunjie 发表于 2016-5-6 20:26
能否举个简单例子? unsafe{}会取变量地址,方法的指针咋取呢?

用this指针指向不行吗
作者: 追忆流年    时间: 2016-5-7 10:39
// Declare delegate -- defines required signature:delegate double MathAction(double num);class DelegateTest{    // Regular method that matches signature:    static double Double(double input)    {        return input * 2;    }    static void Main()    {        // Instantiate delegate with named method:        MathAction ma = Double;        // Invoke delegate ma:        double multByTwo = ma(4.5);        Console.WriteLine("multByTwo: {0}", multByTwo);        // Instantiate delegate with anonymous method:        MathAction ma2 = delegate(double input)        {            return input * input;        };        double square = ma2(5);        Console.WriteLine("square: {0}", square);        // Instantiate delegate with lambda expression        MathAction ma3 = s => s * s * s;        double cube = ma3(4.375);        Console.WriteLine("cube: {0}", cube);    }    // Output:    // multByTwo: 9    // square: 25    // cube: 83.740234375}
//出自MSDN


作者: woshiklc    时间: 2016-5-22 16:15
http://125.confly.eu.org/thread-13899141-1-1.html




欢迎光临 精易论坛 (https://125.confly.eu.org/) Powered by Discuz! X3.4