Eogene

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

DoTest();
}

//Func 委托应用
public event Func<object, int> MyEvent;
#region C#3.0特性
private void DoTest()
{
//Lambda表达式 简化了我们编写事件处理函数的工作
MyEvent += (s) => {
//隐式类型化数组
var temps = new[] {
//匿名类型
new { id = 100, name = "gene", sex = true }
,new { id = 200, name = "gene2", sex = true } };
//Linq查询表达式
var rlt = from t in temps where t.id<200 select t;
foreach (var t in rlt.Where((a) => { return a.sex == true; }))
{
Console.WriteLine(t.id);
}
return 0;
};
MyEvent("Lambda表达式");
}
#endregion
}

static class Extensions
{
/// <summary>
/// //扩展方法 提供了非继承的另一种实现功能扩展的方式。
/// 例:为string 添加ToInt32方法
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static int ToInt32(this string source)
{
return Int32.Parse(source);
}
}
}

posted on 2012-03-09 10:57  EoGene  阅读(116)  评论(0编辑  收藏  举报