一、单个参数(封箱也可实现多参数)

class B
  { 
     public static void Main() 
     {  
        Thread t = new Thread(new ParameterizedThreadStart(Test)); 
        t.Start("a"); 
 
        Console.Read(); 
      } 
 
      private static void Test(object obj) 
      { 
        Console.WriteLine("带一个参数 {0}!",obj.ToString ());  
      } 
   } 
二、多个参数

 class Test2
  { 
     public static void Main() 
     { 
        MyParam m new MyParam(); 
        m.x = 6; 
        m.y = 9; 
 
        Thread t new Thread(new ThreadStart(m.Test)); 
        t.Start(); 
 
        Console.Read(); 
      } 
  } 
  
  class MyParam  
  { 
     public int x, y; 
 
     public void Test() 
     { 
         Console.WriteLine("x={0},y={1}"this.x, this.y); 
     } 
   } 

三、回调函数传参

class C
  { 
     public static void Main() 
     { 
        MyParam m new MyParam(); 
        m.x = 6; 
        m.y = 9; 
        m.callBack = ThreadCallBack;
 
        Thread t new Thread(new ThreadStart(m.Test)); 
        t.Start(); 
 
        Console.Read(); 
     } 
  } 

  private void ThreadCallBack(string msg)
  {
     Console.WriteLine("CallBack:" + msg);  
  }
 
  private delegate void ThreadCallBackDelegate(string msg);

  class MyParam  
  { 
     public int x, y; 
     public ThreadCallBackDelegate callBack;
 
     public void Test() 
     { 
        callBack("x=6,y=9"); 
     } 
   } 

 

相关文章:

  • 2021-09-11
  • 2021-12-28
  • 2021-06-03
  • 2021-11-08
  • 2022-02-08
  • 2021-12-12
  • 2021-06-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案