JavaScript spread syntax in C#

后端 未结 4 574
刺人心
刺人心 2021-01-01 10:26

Is there any implementation in C# like JavaScript\'s spread syntax?

var arr = new []{
   \"1\",
   \"2\"//...
};

Console.WriteLine(...arr);
4条回答
  •  無奈伤痛
    2021-01-01 11:24

    you can also do the following

        var a  = new List(new int[]{1,2,3}){5};
        Console.WriteLine(a.Count);
    

    will print 4

    if you want to achieve initialization of lists or arrays with both an accompanying enumerable and parameters

提交回复
热议问题