在方法调用中创建列表<string>

Mic*_*ard -2 c# methods list

我正在调用一个方法,并希望在其中发送一个字符串列表.是否可以在调用方法时创建列表?

像这样的东西:

methodToCall(int myInt, {"Hello", "World"});
Run Code Online (Sandbox Code Playgroud)

然后像这样检索它:

public static void methodToCall(int myInt, list<string> myStrings)
{
}
Run Code Online (Sandbox Code Playgroud)

Hog*_*gan 7

是的它看起来像这样:

呼叫

 methodToCall(2,new List<string>() {"Hello", "World"});
Run Code Online (Sandbox Code Playgroud)

和这样的函数调用

 public static void methodToCall(int inInt, List<string> inList)
Run Code Online (Sandbox Code Playgroud)