如何在LinqPad中运行下面的代码作为C#程序 谢谢...
class ThreadTest
{
bool done;
static void Main()
{
ThreadTest tt = new ThreadTest(); // Create a common instance
new Thread (tt.Go).Start();
tt.Go();
}
// Note that Go is now an instance method
void Go()
{
if (!done) { done = true; Console.WriteLine ("Done"); }
}
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
此示例 - 以及Nutshell中C#5的并发章节中的所有其他示例都可以作为LINQPad示例库下载.转到LINQPad的样本TreeView,然后单击"下载/导入更多样本"并选择第一个列表. - 乔阿尔巴哈里
刚Main离开,ThreadTest它应该工作正常.您还需要创建类和方法public(或者internal在那时):
static void Main()
{
ThreadTest tt = new ThreadTest(); // Create a common instance
new Thread (tt.Go).Start();
tt.Go();
}
public class ThreadTest
{
bool done;
// Note that Go is now an instance method
public void Go()
{
if (!done) { done = true; Console.WriteLine ("Done"); }
}
}
Run Code Online (Sandbox Code Playgroud)
"C#程序"隐式包含在一个类中 - main在嵌套类中移动可能会混淆Main在最外层类中寻找的执行程序.
| 归档时间: |
|
| 查看次数: |
953 次 |
| 最近记录: |