匿名陣列裡面包含匿名物件之範例
一個匿名陣列裡面包含匿名物件之範例如下
using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var a = new { Amount = 108, Message = "Hello" };
Console.WriteLine($"a.Amount={a.Amount}, a.Message={a.Message}");
var b = new[] {
new {
Amount = 100,
Message = "Hello"
},
new {
Amount = 200,
Message = "Hi"
}
};
foreach (var item in b)
{
Console.WriteLine($"item.Amount={item.Amount}, item.Message={item.Message}");
}
}
}
}
執行結果為
參考資料: