#眉標=Mobile #副標=Windows Mobile開發系列(1) #大標= VS 2008與Windows Mobile 6行動開發新技術 #作者=文/沈炳宏 #引言= ==========程式========= 程式1 C# 2.0 public class Person { private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } private string _lastName; public string LastName { get { return _lastName; } set { _lastName = value; } } private int _age; public int Age { get { return _age; } set { _age = value; } } } C# 3.0 public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } ==========程式========= ==========程式========= 程式2 C# 2.0 Person person = new Person(); person.FirstName = "Bill"; person.LastName = "Shen"; person.Age = 18; C# 3.0 Person person = new Person { FirstName="Bill", LastName="Shen", Age=18 }; C# 3.0 Nested Property Person person = new Person { FirstName = "Bill", LastName = "Shen" Age = 18, Address = new Address { Street = "One Microsoft Way", City = "Redmond", State = "WA", Zip = 98052 } }; ==========程式========= ==========程式========= 程式3 使用物件初始化器 List people = new List(); people.Add( new Person { FirstName = "Bill", LastName = "Shen", Age = 18 } ); people.Add( new Person { FirstName = "YOYO", LastName = "Chen", Age = 8 } ); 使用物件初始化器與集合初始化器 List people = new List { new Person { FirstName = "Bill", LastName = "Shen", Age = 18 }, new Person { FirstName = "YOYO", LastName = "Chen", Age = 8 }}; ==========程式========= ==========程式========= 程式4 string email = Request.QueryString["email"]; if ( EmailValidator.IsValid(email) ) { } ==========程式========= ==========程式========= 程式5 string email = Request.QueryString["email"]; if ( email.IsValidEmailAddress() ) { } ==========程式========= ==========程式========= 程式6 public static class DemoExtensions { public static bool IsValidEmailAddress(this string s) { Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"); return regex.IsMatch(s); } } ==========程式=========