Creating N objects and adding them to a list

You can use the Range to create a sequence:

return Enumerable.Range(0, count).Select(x => new MyObj { bar = foo });

If you want to create a List, you’d have to ToList it.

Mind you though, it’s (arguably) a non-obvious solution, so don’t throw out the iterative way of creating the list just yet.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)