当前位置: 移动技术网 > IT编程>开发语言>c# > C#用匿名方法定义委托的实现方法

C#用匿名方法定义委托的实现方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例讲述了c#用匿名方法定义委托的实现方法。分享给大家供大家参考。具体实现方法如下:

//用匿名方法定义委托 
class program 
{ 
  delegate string mydelagate(string val); 
  static void main(string[] args) 
  { 
    string str1 = " 匿名方法外部 "; 
    //中括号部分定义来了一个方法,没有名称,编译器会定指定一个名称 
    mydelagate my = delegate(string param) 
    { 
      string str2 = " 匿名方法内部 "; 
      return param + str1 + str2; 
    }; 
    //调用委托的匿名方法 
    console.writeline(my(" 参数 ")); 
    //从结果可以看到,匿名方法同样达到了为委托定义方法的效果 
    console.read(); 
  } 
}

希望本文所述对大家的c#程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网