匿名函数

暂时了解的的匿名函数的两种使用方式

1.var d =new{

变量1=值1,

变量2=值2,

。。。。。

}

例1代码:

namespace 匿名类
{
    class Program
    {
        static void Main(string[] args)
        {
           //没有定义类,没有类名
            var d = new {
                ID=123,
                Name="你好"
            };
            Console.WriteLine(d.ID);
            Console.WriteLine(d.Name);
            Console.ReadKey();
        }
    }

2.首先定义一个类

class 类名{

public type 属性1{get;set;}

pubic type 属性2{get;set;}

}

匿名使用该类

var d =new 类名{

属性1=

属性2=

。。。。。

}

namespace 匿名类
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = new Student
            {
                //ID必须是定义的Student类的属性
                ID = 123,
                //Name必须是定义的Student类的属性
                Name = "你好"
            };
            Console.WriteLine(d.ID);
            Console.WriteLine(d.Name);
            Console.ReadKey();
        }

    }
    class Student 
    {
        public int ID { get; set; }

        public string Name { get; set; }
    }

}                                                                
原文地址:https://www.cnblogs.com/cnshuji/p/5507065.html