using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
class AnonymousTypeInArray
{
static void Main()
{
var family = new[]
{
new { Name = "H", Age = 31 },
new { Name = "R", Age = 1 },
new { Name = "W", Age = 1 }
};
int totalAge = 0;
foreach (var person in family)
{
totalAge += person.Age;
}
Console.WriteLine("Total age: {0}", totalAge);
}
}
|