摘要:(200-07-21) LINQ 建構物件
一般建構方式
1.定義類別
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace linqwin { public class Employee { //Data Field //封裝性 private String _id; public String Id { get { return _id; } set { _id = value; } } private String _name; public String Name { get { return _name; } set { _name = value; } } private Decimal _salary; public Decimal Salary { get { return _salary; } set { _salary = value; } } } }
2.建構類別
//一般寫法 Employee emp1 = new Employee(); emp1.Id = "0001"; emp1.Name = "linda"; emp1.Salary = 40000; //物件初始化 var emp = new Employee() { Name = "eric", Id = "0001", Salary=50000 }; MessageBox.Show(emp.Name);
匿名型別建構方式
1.只接使用匿名建構方式建構物件
var emp = new { id="0001", name="linda", address="高雄市", salary=60000 };
課程補充