2012-05-07 91 views
4

对不起,如果这之前已被问过,但我想简要回答以下两种用法之间的差异。 VS似乎接受他们两人作为有效的代码。new Thread(void Target())和new Thread(new ThreadStart(void Target()))有什么区别?

private static void doSomeWork() 
{ 
    //do some work 
} 

public someClass() 
{ 
    //Thread thread = new Thread(doSomeWork); 
    //or 
    //Thread thread = new Thread(new ThreadStart(doSomeWork)); 
} 
+1

看看http://stackoverflow.com/questions/3360555/how-to-pass-parameters-to-threadstart-method-in-thread –

+0

非常相似:http://stackoverflow.com/questions/2749868/new-eventhandlermethod-vs-method – CodesInChaos

+0

[C#Delegate Instantiation vs. Just Passing the Method Reference]可能的重复(http://stackoverflow.com/questions/2181282/c-sharp-delegate-instantiation-vs-just -passing-the-method-reference) – nawfal

回答

6

唯一的区别在于,第一个不工作在C#1的C#2的编译器和后,转换的第一个到第二个。

方法组可隐式转换为具有兼容签名的委托类型。该功能被称为“(隐式)方法组转换”。有时你需要第二个指导重载解决方案,但这不是这种情况。

+0

很快。谢谢,答案非常清楚。 –

相关问题