Shortest way to create a List of a repeated element

前端 未结 3 738
野性不改
野性不改 2021-02-06 21:36

With the String class, you can do:

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

What\'s the shortest way to create a List< T > th

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-06 21:51

    This seems pretty straight-forward ...

    for( int i = 0; i < n; i++ ) { lst.Add( thingToAdd ); }
    

    :D

提交回复
热议问题