爲什麼我不能使用下面的選項#1。選項2正常工作爲什麼我得到這個編譯錯誤?
class Program
{
static void Main()
{
//Option 1
//Error 1 The best overloaded method match for 'ConsoleApplication2.Program.SomeMethod(System.Collections.Generic.List<string>)' has some invalid argument
//Error 2 Argument 1: cannot convert from 'void' to 'System.Collections.Generic.List<string>'
SomeMethod(new List<string>().Add("This give compilation Error"));
//Option 2
List<string> MyMessages = new List<string>();
MyMessages.Add("This compiles fine");
SomeMethod(MyMessages);
}
static void SomeMethod(List<string> Messages)
{
foreach (string Message in Messages)
Console.WriteLine(Message);
}
}
其他答案是正確的,因爲他們指出我正在做的愚蠢的事情,但這是我真正想做的事情。謝謝全部 – 2011-12-14 15:27:19