using System;
using System.Collections.Generic;
namespace 匿名函数
{
public delegate void MyDel();
public delegate double MyDel2(double a);
class MainClass
{
public static void Main (string[] args)
{
MyDel md = delegate(){ Console.WriteLine ("md1 这里是匿名函数1的方法体");};
md();//如果一个方法只调用一次,那么我们就可以将它写为匿名函数
MyDel2 md2 = delegate(double a){Console.WriteLine ("md2 这里是匿名函数2的方法体"); return a;};
Console.WriteLine ( md2(55555));
//lanmda 表达式
MyDel md3 = ()=>{Console.WriteLine("md3 这里是lambda表达式的方法体");};
md3 ();//上面的那一行只是定义,只有写了下面的md3();才可以对函数进行实现
//删除比一个数小的数
List<int> list = new List<int>();
list.AddRange (new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
list.RemoveAll (b => b <= 4);//把小于等于4的数字移除
foreach (var item in list) {
Console.WriteLine (item);
}
}
}
using System.Collections.Generic;
namespace 匿名函数
{
public delegate void MyDel();
public delegate double MyDel2(double a);
class MainClass
{
public static void Main (string[] args)
{
MyDel md = delegate(){ Console.WriteLine ("md1 这里是匿名函数1的方法体");};
md();//如果一个方法只调用一次,那么我们就可以将它写为匿名函数
MyDel2 md2 = delegate(double a){Console.WriteLine ("md2 这里是匿名函数2的方法体"); return a;};
Console.WriteLine ( md2(55555));
//lanmda 表达式
MyDel md3 = ()=>{Console.WriteLine("md3 这里是lambda表达式的方法体");};
md3 ();//上面的那一行只是定义,只有写了下面的md3();才可以对函数进行实现
//删除比一个数小的数
List<int> list = new List<int>();
list.AddRange (new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
list.RemoveAll (b => b <= 4);//把小于等于4的数字移除
foreach (var item in list) {
Console.WriteLine (item);
}
}
}
}