IEnumerable
doesn’t support this. This is by design. IEnumerable
uses lazy evaluation to get the elements you ask for just before you need them.
If you want to know the number of items without iterating over them you can use ICollection<T>
, it has a Count
property.
More Related Contents:
- The order of elements in Dictionary
- How to get the index of an element in an IEnumerable?
- ReadOnlyCollection or IEnumerable for exposing member collections?
- Pair-wise iteration in C# or sliding window enumerator
- Passing a single item as IEnumerable
- How to check if IEnumerable is null or empty?
- When a class is inherited from List, XmlSerializer doesn’t serialize other attributes
- IEnumerable to string [duplicate]
- What is the difference between IEnumerator and IEnumerable? [duplicate]
- How to concatenate two IEnumerable into a new IEnumerable?
- Collection was modified; enumeration may not execute error when removing a ListItem from a LIstBox
- IEnumerable vs IReadonlyCollection vs ReadonlyCollection for exposing a list member
- Difference between IEnumerable Count() and Length
- Is there an IEnumerable implementation that only iterates over it’s source (e.g. LINQ) once?
- Pair-wise iteration in C#, or sliding window enumerator
- What is the purpose of AsQueryable()?
- IEnumerable and order
- Why do arrays in .net only implement IEnumerable and not IEnumerable?
- Is it possible to extend arrays in C#?
- Map two lists into a dictionary in C#
- generic NOT constraint where T : !IEnumerable
- HTML.ActionLink method
- Best way to repeat a character in C#
- how to implement url rewriting similar to SO
- How can I tell if my process is running as Administrator?
- How to get the location of the DLL currently executing?
- How to omit methods from Swagger documentation on WebAPI using Swashbuckle
- Entity Framework Core: Guid Greater Than for Paging
- Ensure that HttpConfiguration.EnsureInitialized()
- How to compare two images?