Feature Request: Syntax Sugar for AddRange in List Initialization
Dogwei opened this issue · comments
陈鑫伟 commented
I would like to propose a new syntax for Roslyn. Here is the idea:
Currently, if we want to initialize a list with an array and some other elements, we have to do something like this:
var array = new int[] { 1, 2, 3 };
var list = new List<int>();
list.Add(1);
list.AddRange(array);
list.Add(2);
list.AddRange(array);
list.Add(3);
Referring to the syntax of other languages, I propose a new syntax that allows us to do the same thing more concisely:
var array = new int[] { 1, 2, 3 };
var list = new List<int>
{
1,
...array,
2,
...array,
3,
};
In this proposed syntax, ...array
would be equivalent to AddRange(array)
. This would make the code more readable and easier to write.