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

后端 未结 4 1515
说谎
说谎 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:38

    you can do this :

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

    provided all the objects are of the same type you don't need to specify the type in the array definition

提交回复
热议问题