Chinaunix首页 | 论坛 | 博客
  • 博客访问: 500991
  • 博文数量: 60
  • 博客积分: 2673
  • 博客等级: 少校
  • 技术积分: 700
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-09 00:25
个人简介

目前主要从事C++软件开发

文章分类

全部博文(60)

文章存档

2013年(3)

2012年(3)

2010年(6)

2009年(23)

2008年(25)

我的朋友

分类:

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();
        }
    }



}

阅读(1411) | 评论(0) | 转发(0) |
0

上一篇:CXPButton

下一篇:2009计算机考研试题

给主人留下些什么吧!~~