I may only be asking this because I've blinded myself to something brilliantly obvious but,
I'm looking for something like this...
IEnumerable<Foo> fooSeq = Enumerable.Generate(()=> new Foo(), 5);
which would make fooSeq a sequence of 5 new Foo instances.
Can't seem to find it though.
IEnumerable. Any() will return true if there are any elements in the sequence and false if there are no elements in the sequence. This method will not iterate the entire sequence (only maximum one element) since it will return true if it makes it past the first element and false if it does not.
What you can do is use the Add extension method to create a new IEnumerable<T> with the added value. var items = new string[]{"foo"}; var temp = items; items = items. Add("bar");
IEnumerable doesn't have a Count method.
Not sure what exactly you are trying to do but if you are trying to generate 5 Foo instances, this will work
IEnumerable<Foo> fooSeq = Enumerable.Range(1, 5).Select(x => new Foo())
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