All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
为什么PHP令人不爽(对于大型系统)_php资料_编程技术
PHP技巧:使用APC缓存优化PHP程序_php资料_编程技术
常用网页设计效果代码十五例_[Html教程]
ASP.NET,2.0后台代码与内联代码的对比_[Asp.Net教程]
visual c++中的画刷类CBrush使用实例
帮助你如何迅速优化你MySQL数据库性能_php资料_编程技术
用ASP.Net编写的查询域名的程序_[Asp.Net教程]
最简单快速的Apache二级域名实现方法介绍_[PHP教程]
资深网管教你一步步安装MYSQL数据库_[PHP教程]
ASP连接SQL2000的方法_[SQL,Server教程]
Reading number is top 10 pictures
2015中美最新武器装备巅峰对决!
Sell the barbecue as says father du breul3
Ashlynn Brooke show proud chest measurement1
Fierce! China's special forces training the devil2
NeedWallpaper11
色狗系列
Startling Russian girl blind date scene3
Abdominal hit by iron--HangZhou best driver parking save passengers
Send some Valentine's day cartoon
王艳写真温柔如水2
Download software ranking
终极变速大师Speeder3.26
Boxer vs Yellow4
C语言教程TXT
Boxer vs Yellow1
Sora aoi - one of more PK
c#程序设计案例教程
Call Of Duty5
Boxer's Top ten classic battle9
Unix video tutorial11
Ashlynn Video5
delv published in(发表于) 2014/1/6 9:08:43 Edit(编辑)
了解c#2.0中的Anonymous,Methods(匿名方法)_[Asp.Net教程]

了解c#2.0中的Anonymous,Methods(匿名方法)_[Asp.Net教程]

了解c#2.0中的Anonymous Methods(匿名方法)_[Asp.Net教程]

Anonymous Methods 是 C#2.0的新特性之一,它允许我们在代码中创建一个内置的没有方法名的方法,将代码与委托实例相关联,从而使委托的实例化工作更加直观和方便,提高了代码的可读性和可维护性。下面来看一个简单的匿名方法的使用:

private int[] _integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };


int[] evenIntegers = Array.FindAll(_integers, delegate(int integer)
{
return (integer%2 == 0);
}
);


上面的代码使用了匿名方法来获得数组中能被2整除的数,其中的匿名方法是:


delegate(int integer)
{
return (integer%2 == 0);
}


如果我们不用匿名方法,我们就需要专门创建一个方法,如下:


private int[] _integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };


int[] evenIntegers = Array.FindAll(_integers, IsEven);


private bool IsEven(int integer)
{
return (integer%2 == 0);
}


匿名方法用于那种方法比较简单,而且不会在其他地方被调用的情况,我们还可以像下面这样用匿名方法:


button1.Click +=


delegate
{
MessageBox.Show("Hello");
};


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.