T>最短创建一个列表与其中的方式;重复的元素最短、创建一个、元素、方式

2023-09-04 23:41:11 作者:你眼里有星星

使用String类,你可以这样做:

With the String class, you can do:

string text = new string('x', 5);
//text is "xxxxx"

什么是创建一个列表与其中最短的途径; T>这是充满了 N 这些都是相同的参考因素?

What's the shortest way to create a List< T > that is full of n elements which are all the same reference?

推荐答案

请尝试以下

var l = Enumerable.Repeat('x',5).ToList();