linq

Action act1=new Action(delegate(){console.WriteLine("这是方法体");});//2.0匿名方法

//3.0 lamd

Action act2=new Action(()=>{Console.WriteLine("这是方法体")});去掉delegate  => gosto   为lambd

Action act3=new Action(()=>Console.WriteLine("这是方法体"));去掉{}

Action act4=()=>console.WriteLine("这是方法体");去掉new Action

Action<string,int> act5=(s,i)=>{console.WriteLine($"{s},age:{i}")};

有返回值的委托

Func<int> func1 = () => 1;

Func<string, int, int> func2 = (s, i) => { Console.WriteLine($"{s}年龄{i}");return i+10; };

Console.WriteLine($"年龄:{func2("李四",15)}");

//3.0 匿名类

object m=new{

  Id=1,

  Name="张三"

}

m.Id   //无法访问   静态类型决定了没有Id属性   编译器只知道是object类型   不知道里面有Id

4.0 dynamic    避开编译器的检查

dynamic dM=new{

  Id=2,

  Name="李四";

}

Console.Write(dM.Id);//这个是正常

Console.WriteLine(dM.OOOOO);//编译器不会报错,运行的时候汇报错

3.0   var         泛型匿名类  语法糖                 自动推算类型  1、 配合匿名类型使用 2、偷懒,复杂类型的使用

var vM=new{

  Id=3,Name=“王五”

}

Console。Write(vM.Id)

============================================

扩展方法 3.0

public static class ExtendMethod{

  public static int Toint(this int iValue){return -iValue;}

}

 正常 实例访问自己的方法   

不修改类型(类)的前提下,为类型增加行为(方法)。

扩展第三方的类

如果原类有方法(方法名),再创建相同的扩展方法(方法名),调用的是原有方法!!!

 =========================================================

Enumerable 是一个静态类,里面全是扩展方法。

IEnumerable 是一个接口 一个方法GetEnumerator()

IEnumerabel<out T> :IEnumerable是一个泛型接口继承

List 是一个泛型类 里面有很多方法

 泛型约束 where T:class 引用类型约束

where T:struct  值类型约束

原文地址:https://www.cnblogs.com/mingjing/p/7850333.html