扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:朱先忠 来源:天极网 2007年11月17日
关键字: 软件
public class Person { private string name; public Person(){} public Person(string name) { this.name = name; } public string Name { get{ return name; } set{ name = value; } } public string GetUpperName() { return name.ToUpper(); } public string UpperName { get{ return GetUpperName(); } set{} } } |
public class Person { /// <remarks/> public string Name; } |
using System; using System.Reflection; using System.Diagnostics; using System.Xml.Serialization; namespace BusinessCollections { [Serializable()] public class PersonCollection : System.Collections.CollectionBase { public static PersonCollection CreateNew() { PersonCollection persons = new PersonCollection(); persons.Add(new Person("Paul")); persons.Add(new Customer("David", "Cadyville")); persons.Add(new Employee("Kathy", 50000M)); return persons; } public Person this[int index] { get{ return (Person)List[index]; } set{ List[index] = value; } } public int Add(Person value) { return List.Add(value); } public PersonCollection Select(Type type) { PersonCollection persons = new PersonCollection(); foreach(Person p in List) { if( p.GetType().Equals(type)) persons.Add(p); } return persons; } public void Dump() { foreach(Person person in this) { Debug.WriteLine(string.Format("Type: {0}",person.GetType().FullName)); PropertyInfo[] properties = person.GetType().GetProperties(); foreach(PropertyInfo p in properties) { try { Debug.WriteLine(string.Format("Name: {0}, Value: {1}",p.Name, p.GetValue(person, null))); } catch { Debug.WriteLine(string.Format("Name: {0}, Value: {1}",p.Name, "unknown")); } } } } } public class Person { private string name; public Person(){} public Person(string name) { this.name = name; } public string Name { get{ return name; } set{ name = value; } } public string GetUpperName() { return name.ToUpper(); } public string UpperName { get{ return GetUpperName(); } set{} } } public class Employee : Person { private decimal salary; public Employee() : base(){} public Employee(string name) : base(name){} public Employee(string name, decimal salary) : base(name) { this.salary = salary; } public decimal Salary { get{ return salary; } set{ salary = value; } } } public class Customer : Person { private string city; public Customer() : base(){} public Customer(string name) : base(name){} public Customer(string name, string city) : base(name) { this.city = city; } public string City { get{ return city; } set{ city = value; } } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者