How can I quickly create a string list with numbered strings?
Right now I'm using:
var str = new List<string>();
for (int i = 1; i <= 10; i++)
{
str.Add("This is string number " + i);
}
This works, however I wonder if there's a quicker way to initialize such a string list, maybe in one or two lines?
You could use LINQ:
Enumerable.Range(1, 10).Select(i => "This is string number " + i).ToList();
var str = Enumerable.Range(1, 10).Select(i => "This is string number " + i).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With