c#线程间传递参数
作者:网络转载 发布时间:[ 2013/12/20 10:32:45 ] 推荐标签:
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace AAAAAA
{
class AAA
{
public static void Main()
{
My m = new My();
m.x = 2;
m.y = 3;
Thread t = new Thread(new ThreadStart(m.C));
t.Start();
Console.Read();
}
}
class My
{
public int x, y;
public void C()
{
Console.WriteLine("x={0},y={1}", this.x, this.y);
}
}
}
|
结果显示x=2,y=3
四、利用结构体给参数传值。
定义公用的public struct结构体,里面可以定义自己需要的参数,然后在需要添加线程的时候,可以定义结构体的实例。
|
view plaincopy to clipboardprint?
//结构体
struct RowCol
{
public int row;
public int col;
};
//定义方法
public void Output(Object rc)
{
RowCol rowCol = (RowCol)rc;
for (int i = 0; i < rowCol.row; i++)
{
for (int j = 0; j < rowCol.col; j++)
Console.Write("{0} ", _char);
Console.Write("/n");
}
}
|
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。

sales@spasvo.com