読者です 読者をやめる 読者になる 読者になる

C# 3.0 - 匿名型配列

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Program
{
    class Program
    {
        static void Main(string[] args)
        {
            var persons = new[]
                        {
                            new { Age = 22, Name = "Akira" },
                            new { Age = 38, Name = "Bob" }
                        };

            foreach (var person in persons) {
                Console.WriteLine("年齢:{0}, 名前:{1}", person.Age, person.Name);
            }
        }
    }
}