Initializing a string array in a method call as a parameter in C#

后端 未结 4 1517
说谎
说谎 2021-01-17 22:53

If I have a method like this:

public void DoSomething(int Count, string[] Lines)
{
   //Do stuff here...
}

Why can\'t I call it like this?<

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-17 23:37

    You can construct it while passing it in like so:

    DoSomething(10, new string[] { "One", "Two", "Three"});
    

提交回复
热议问题