I need to create pairs / triples of something and store it somewhere. How can I do it?
I tried:
for (int i = 0; i < 100; i++)
{
var item=new { a=i , b="lala" ,c=4.5m}; //anonymous type
}
But then I thought: List<what>
?
I could use dynamic but I want Intellisense.
(I could have also use Tuple<int,string,decimal>
but if I already have what I need (=new { a=i , b="lala" ,c=4.5m};
), why should I use other type (tuple)? )
Is there any solution to this?
You can use type inference
var items = Enumerable.Range(0,100)
.Select(i => new { a=i , b="lala", c=4.5m })
.ToList(); // not necessary (you can use IEnumerable)
Not sure, how you fill fields within for
, but could you try:
var lstOfSmth = Enumerable.Range(0, 100)
.Select(i => new { a = i, b = "lala", c = 4.5m })
.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