字号: 小 中 大 |
推荐给好友
上一篇 |
下一篇
Hashtable的用法
发布: 2007-7-01 20:40 |
作者: admin |
来源:
|
查看: 43次 | 进入软件测试论坛讨论
领测软件测试网
这个例子演示了Hashtable的用法,例子比较简单,主要是下面两个类的一些方法的override:
public class EmployeeID { private readonly char prefix; private readonly int number;
public EmployeeID( string id ) { prefix = (id.ToUpper())[0]; number = int.Parse ( id.Substring(1,3) ); }
public override string ToString() { return prefix.ToString () + string.Format( "{0,3:000}",number ); } public override int GetHashCode() { return this.ToString().GetHashCode(); } public override bool Equals(object obj) { EmployeeID rhs = obj as EmployeeID ; if( rhs == null ) return false; if( prefix == rhs.prefix && number == rhs.number ) return true; return false; }
} |
public class EmployeeData { private string name; private decimal salary; private EmployeeID id;
public EmployeeData( EmployeeID id, string name, decimal salary) { this.id = id; this.name = name; this.salary = salary; }
public override string ToString() { StringBuilder sb = new StringBuilder( id.ToString(), 100 ); sb.Append (": "); sb.Append ( string.Format( "{0,-20}", name)); sb.Append (" "); sb.Append (string.Format ( "{0:C}",salary)); return sb.ToString (); }
} |
具体的请参考源代码。
文章来源于领测软件测试网 https://www.ltesting.net/