单个对象
new { Inv = item.Inv, Count = item.Count }
数组
var testData = new[] { new {Name="Test1", Top=1}, new {Name="Test2", Top=2}, new {Name="Test3", Top=3}, new {Name="Test4", Top=4}, new {Name="Test5", Top=5}, new {Name="Test6", Top=6}, new {Name="Test7", Top=7}, new {Name="Test8", Top=8}, new {Name="Test9", Top=9} };
还可以声明多个相同的匿名对象格式,C#会自动识别成一个
这里把两个字符串合成为一种匿名对象的数组
var str1 = "Mike,12|Tom,5|Jhon,7"; var str2 = "Sam,80|Eric,60"; var memberArray = str1 .Split('|') .Select(m => new {ID = m.Split(',')[0], Score = m.Split(',')[1]}) .Concat(str2 .Split('|') .Select(m => new {ID = m.Split(',')[0], Score = m.Split(',')[1]})) .ToArray(); foreach (var item in memberArray) { Debug.Log("ID: " + item.ID + " Score: " + item.); }