How can I avoid IEnumerable multiple iterations? Is it bad to cast IEnumerable --> ICollection --> IEnumerable to perform validation?

This page summarizes the projects mentioned and recommended in the original post on /r/dotnet

Our great sponsors
  • InfluxDB - Collect and Analyze Billions of Data Points in Real Time
  • Mergify - Updating dependencies is time-consuming.
  • SonarQube - Static code analysis for 29 languages.
  • AsyncEx

    A helper library for async/await.

    BTW - My use-case is that I am developing nuget packages. My nuget packages are lower level, similar to this:

  • silverback

    Silverback is a simple but feature-rich message bus for .NET core (it currently supports Kafka, RabbitMQ and MQTT).

    I tend to declare the parameter as IReadOnlyCollection because I can safely iterate without extra allocations. I know you could just do a ToList by default but it would mean allocating a few arrays in the process, in worst case. You could be smarter and check if the IEnumerable can be casted to IReadOnlyCollection and perform a ToList only when needed, this would be the most flexible implementation. I sometimes create an extension method for this:

  • InfluxDB

    Collect and Analyze Billions of Data Points in Real Time. Manage all types of time series data in a single, purpose-built database. Run at any scale in any environment in the cloud, on-premises, or at the edge.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts