A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 张旭 黑马帝   /  2011-12-12 23:17  /  2178 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

threadstart 和 ParameterizedThreadStart 区别

评分

参与人数 1技术分 +2 收起 理由
李荣壮 + 2

查看全部评分

1 个回复

倒序浏览
乔克 黑马帝 2011-12-13 08:35:59
沙发
本帖最后由 乔克 于 2011-12-13 08:36 编辑

1.threadstart :不需要传递参数,也不需要返回参数。
  1. ThreadStart threadStart=new ThreadStart(Calculate);
  2. Thread thread=new Thread(threadStart);
  3. thread.Start();
  4. public void Calculate()

  5.    {
  6.  double Diameter=0.5;
  7.  Console.Write("The Area Of Circle with a Diameter of {0} is {1}"Diameter,Diameter*Math.PI);
  8. }
复制代码
2.ParameterizedThreadStart需要传递单个参数
  1. ParameterizedThreadStart threadStart=new ParameterizedThreadStart(Calculate)
  2. Thread thread=new Thread() ;

  3. thread.Start(0.9);

  4. public void Calculate(object arg)

  5. {
  6. double Diameter=double(arg);
  7. Console.Write("The Area Of Circle with a Diameter of {0} is {1}"Diameter,Diameter*Math.PI);
  8. }
复制代码
Calculate方法有一个为object类型的参数,虽然只有一个参数,而且还是object类型的,使用的时候尚需要类型转换,但是好在可以有参数了,并且通过把多个参数组合到一个类中,然后把这个类的实例作为参数传递,就可以实现多个参数传递.
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马