110,533
社区成员
发帖
与我相关
我的任务
分享
class MyClass
{
static void Main(string[] args)
{
object o = new { };
System.Console.WriteLine(o.GetType());
System.Console.ReadKey();
}
}
//<>f__AnonymousType0
using System.Collections.Generic;
using System;
class P
{
delegate string X(string name);
static void Main()
{
var obj = new { Name = "crab",
Age = 23,
SayHello = (X)((string name) => string.Format( "Hello, {0}!", name ))
};
}
}
staticvoid Main(string[] args)
{
var stu=new { Name="XiaoShan", Age=21 };
Console.WriteLine(stu.Name);
}
楼主不妨试一下这段代码,很简单,一看就懂了
static void Main(string[] args)
{
var stu = new { Name = "XiaoShan", Age = 21 };
Console.WriteLine(stu.Name);
}
using System;
class MyClass
{
static void Main(string[] args)
{
object o1 = new { };
object o2 = new { };
object o3 = new { i = 1, s = "abc" };
object o4 = new { s = "eee", i = 1 };
f__AnonymousType type = new
System.Console.WriteLine("o1:{0},o2:{1},o3:{2},o4:{3}", o1.GetType(), o2.GetType(), o3.GetType(), o4.GetType());
System.Console.ReadKey();
}
}
//o1:<>f__AnonymousType0,
//o2:<>f__AnonymousType0,
//o3:<>f__AnonymousType1`2[System.Int32,System.String],
//o4:<>f__AnonymousType2`2[System.String,System.Int32]