知识改变人生zzz.blog.chinaunix.net
zhangzhenzhong
目前主要从事C++软件开发
全部博文(60)
2013年(3)
2012年(3)
2010年(6)
2009年(23)
2008年(25)
songlw41
garyhuc
cff23674
84378567
格伯纳
Bsolar
qq9402
胡田新
屌丝变态
nhgy200
分类:
2009-03-08 17:26:54
1.Clone()方法的使用
namespace zhangzhenzhong{ public class Starter { public static void Main() { CommissionedEmployee[] salespeople= {new CommissionedEmployee ("Bob"), new CommissionedEmployee ("Ted"), new CommissionedEmployee ("Sally")}; Employee[] employees=(Employee[])salespeople.Clone(); foreach(Employee person in employees) { person.Pay(); } Console.Read(); } } public class Employee { public Employee(string name) { m_Name=name; } public virtual void Pay() { Console.WriteLine("Paying {0}",m_Name); } private string m_Name; } public class CommissionedEmployee:Employee { public CommissionedEmployee(string name) : base(name) { } public override void Pay(){ base.Pay(); Console.WriteLine("Paying Commissions"); } }}
2.数组中线程的使用。
namespace zhangzhenzhong{ public class Starter { private static int[] zArray= { 10,1,5,2,3,6,7,8,9,4 }; public static void DisplayForward() { lock(zArray.SyncRoot) { Console.Write("\nForWard:"); foreach(int number in zArray) { Console.Write(number); } } } public static void DisplayReverse() { lock(zArray.SyncRoot) { Array.Reverse(zArray); Console.Write("\nReverse:"); foreach(int number in zArray) { Console.Write(number); } Array.Reverse(zArray); } } public static void Main() { Array.Sort(zArray); Thread t1=new Thread(new ThreadStart(DisplayForward)); Thread t2=new Thread(new ThreadStart(DisplayReverse)); t1.Start(); t2.Start(); Console.Read(); } }}
上一篇:CXPButton
下一篇:2009计算机考研试题
登录 注册