&引用;System.threading.threadStart';是一个';类型';,在给定的上下文中无效;?(C#)
我在&引用;System.threading.threadStart';是一个';类型';,在给定的上下文中无效;?(C#),c#,.net,multithreading,delegates,lambda,C#,.net,Multithreading,Delegates,Lambda,我在var ts=System.Threading.ThreadStart(delegate()(红线已淹没在System.Threading.ThreadStart)上遇到错误。问题是什么 using System; using System.Threading; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class P
var ts=System.Threading.ThreadStart(delegate()
(红线已淹没在System.Threading.ThreadStart
)上遇到错误。问题是什么
using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public Program()
{
int[] iArray = new int[3];
iArray[0] = 2;
iArray[1] = 1;
iArray[2] = 5;
var ts = System.Threading.ThreadStart(delegate()
{
foreach (int i in iArray)
Foo(i);
});
}
public void Foo(int i)
{
Console.WriteLine(i + ",");
}
public static void Main(String[] args)
{
Program p = new Program();
}
}
}
您缺少一个新的
:
var ts = new System.Threading.ThreadStart(delegate()
{
foreach (int i in iArray)
Foo(i);
});
顺便说一句:
你不必在ThreadStart
前面加上它的名称空间System.Threading
,因为在你的*.cs文件的顶部已经有了一个using
声明。好吧,…我不知道是要感谢你解决了这个问题,还是要生你的气,因为你让我知道我有多愚蠢。但我只是很抱歉丁。我应该多加注意。谢谢!:)