匿名类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/* 1、匿名类型只能和局部变量配合使用,不能用于类成员
* 2、匿名类型没有名字,必须用var关键词作为变量类型
* 3、变量声明的三种形式:赋值形式、成员访问、标识符
*/
namespace 匿名类
{
class Other
{
static public string Name = "SuLONG";
}
class Program
{
static void Main(string[] args)
{
var student = new { LName = "sulong", FName = "xu", Age = 23, Major = "IOT" };
Console.WriteLine("{0} {1},Age:{2},Major:{3}",student.FName,student.LName,student.Age,student.Major);
string major = "IOT";
var people = new { Age = 23, Other.Name, major };//赋值形式、成员访问、标识符
//等同于var people = new { Age = 23, Other.Name, major };
Console.WriteLine("{0} {1},Age:{2},Major:{3}", student.FName, student.LName, student.Age, student.Major);
Console.ReadKey();
}
}
}