我为什么不能使用下面的选项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);
}
}