
C#大问题,高分求救!!!! 20
classTest(){staticvoidMain(){Threadth1=newThread(newThreadStart(h1));Threadth2=newThr...
class Test()
{
static void Main()
{
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
不知道为什么就错了!~!~
不好意思是题目打错了!~因该是这样!~我要这样打出(呵呵)
class Test()
{
Thread th1;
Thread th2;
static void Main()
{
th1=new Thread(new ThreadStart(h1));
th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
} 展开
{
static void Main()
{
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
不知道为什么就错了!~!~
不好意思是题目打错了!~因该是这样!~我要这样打出(呵呵)
class Test()
{
Thread th1;
Thread th2;
static void Main()
{
th1=new Thread(new ThreadStart(h1));
th2=new Thread(new ThreadStart(h2));
th1.IsbackGround=true;
th2.IsbackGround=true;
th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
} 展开
展开全部
//你可以用静态方法,参考以下代码:
//定义Class不能加括号
//class Test()
class Test
{
//Main是静态方法不能调直接用动态变量
//Thread th1;
//Thread th2;
static Thread th1;
static Thread th2;
static void Main()
{
th1 = new Thread(new ThreadStart(h1));
th2 =new Thread(new ThreadStart(h2));
//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
th1.IsBackground = true;
th2.IsBackground = true;
th1.Start();
}
//Main是静态方法不能调直接用动态方法
//void h1()
static void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
//Main是静态方法不能调直接用动态方法
//void h2()
static void h2()
{
Console.WriteLine("呵呵");
}
}
//----------------------------------------------------------//
//你也可以创那一个静态变量,使用它的动态方法,参考以下代码:
//定义Class不能加括号
//class Test()
class Test2
{
Thread th1;
Thread th2;
//使用t2创建th1和th2
static Test2 t2 = new Test2();
static void Main()
{
//th1 = new Thread(new ThreadStart(h1));
//th2 = new Thread(new ThreadStart(h2));
t2.th1 = new Thread(new ThreadStart(t2.h1));
t2.th2 = new Thread(new ThreadStart(t2.h2));
//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
t2.th1.IsBackground = true;
t2.th2.IsBackground = true;
t2.th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
t2.th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
//定义Class不能加括号
//class Test()
class Test
{
//Main是静态方法不能调直接用动态变量
//Thread th1;
//Thread th2;
static Thread th1;
static Thread th2;
static void Main()
{
th1 = new Thread(new ThreadStart(h1));
th2 =new Thread(new ThreadStart(h2));
//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
th1.IsBackground = true;
th2.IsBackground = true;
th1.Start();
}
//Main是静态方法不能调直接用动态方法
//void h1()
static void h1()
{
Console.WriteLine("哈哈");
th2.Start();
}
//Main是静态方法不能调直接用动态方法
//void h2()
static void h2()
{
Console.WriteLine("呵呵");
}
}
//----------------------------------------------------------//
//你也可以创那一个静态变量,使用它的动态方法,参考以下代码:
//定义Class不能加括号
//class Test()
class Test2
{
Thread th1;
Thread th2;
//使用t2创建th1和th2
static Test2 t2 = new Test2();
static void Main()
{
//th1 = new Thread(new ThreadStart(h1));
//th2 = new Thread(new ThreadStart(h2));
t2.th1 = new Thread(new ThreadStart(t2.h1));
t2.th2 = new Thread(new ThreadStart(t2.h2));
//C#区分大小写
//th1.IsbackGround=true;
//th2.IsbackGround=true;
t2.th1.IsBackground = true;
t2.th2.IsBackground = true;
t2.th1.Start();
}
void h1()
{
Console.WriteLine("哈哈");
t2.th2.Start();
}
void h2()
{
Console.WriteLine("呵呵");
}
}
展开全部
一楼正确
你在Main函数中声明的th1,th2
h1函数中可不知道th2为何物.
你把
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
放在Main函数的外面声明就没问题了
你在Main函数中声明的th1,th2
h1函数中可不知道th2为何物.
你把
Thread th1=new Thread(new ThreadStart(h1));
Thread th2=new Thread(new ThreadStart(h2));
放在Main函数的外面声明就没问题了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼主你能看懂他们在说什么吗?其实你也看的不太清楚而已,你不如直接在摆渡搜索一下就可以得到答案的,不用这么浪费时间和得给分。。谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你最后的时候把 th1 th2. Abort() 下,试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
th2在h1方法中没有声明
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询