C#3.0技术探讨(4):集合初始化器Collection Initializer
/*--===------------------------------------------===---
集合初始化器: Collection Initializer
许明会 2007/12/3 19:41
--===------------------------------------------===---*/
using System;
using System.Collections.Generic;
namespace xumh
{
public class student
{
public string Name{get;set;}
public int Age{get;set;}
public string Address{get;set;}
};
public class runMyApp
{
static void Main()
{
List<student> stu = new List<student> {
new student{Name="许明会", Age=36, Address="北大青鸟"},
new student{Name="林松涛", Age=34, Address="正海集团"},
new student{Name="刘向阳", Age=35, Address="LG伊诺特"}
};
foreach(var v in stu)
{
Console.WriteLine("{0},今年{1}岁,就职于{2}",
v.Name, v.Age, v.Address);
}
}
};
}
集合初始化器: Collection Initializer
许明会 2007/12/3 19:41
--===------------------------------------------===---*/
using System;
using System.Collections.Generic;
namespace xumh
{
public class student
{
public string Name{get;set;}
public int Age{get;set;}
public string Address{get;set;}
};
public class runMyApp
{
static void Main()
{
List<student> stu = new List<student> {
new student{Name="许明会", Age=36, Address="北大青鸟"},
new student{Name="林松涛", Age=34, Address="正海集团"},
new student{Name="刘向阳", Age=35, Address="LG伊诺特"}
};
foreach(var v in stu)
{
Console.WriteLine("{0},今年{1}岁,就职于{2}",
v.Name, v.Age, v.Address);
}
}
};
}