Night Walker
Night Walker

Reputation: 21260

Populate list with the same number

How I can convert this code to LINQ?

var TcData = new List<double>();

for(int i=0;i< numberTcs ;++i)
{
    TcData.Add(-1);
}

Upvotes: 3

Views: 141

Answers (2)

Kent Boogaart
Kent Boogaart

Reputation: 178630

TcData = Enumerable.Repeat(-1d, numberTcs).ToList();

Upvotes: 7

max
max

Reputation: 34407

TcData = new List<double>(Enumerable.Repeat<double>(-1, numberTcs));

Upvotes: 2

Related Questions