Differences between IQueryable, List, IEnumerator?

IQueryable<T> is intended to allow a query provider (for example, an ORM like LINQ to SQL or the Entity Framework) to use the expressions contained in a query to translate the request into another format. In other words, LINQ-to-SQL looks at the properties of the entities that you’re using along with the comparisons you’re making … Read more

Params IEnumerable c#

Why cant I use an IEnumerable with params? The question presupposes that the design team must provide a reason to not add a feature to the language. This presupposition is false. Rather, in order for a feature to be used by you it needs to be thought of, designed, specified, implemented, tested, documented and shipped. … Read more

Does C# have IsNullOrEmpty for List/IEnumerable?

nothing baked into the framework, but it’s a pretty straight forward extension method. See here /// <summary> /// Determines whether the collection is null or contains no elements. /// </summary> /// <typeparam name=”T”>The IEnumerable type.</typeparam> /// <param name=”enumerable”>The enumerable, which may be null or empty.</param> /// <returns> /// <c>true</c> if the IEnumerable is null or … Read more

Difference between IEnumerable Count() and Length

By calling Count on IEnumerable<T> I’m assuming you’re referring to the extension method Count on System.Linq.Enumerable. Length is not a method on IEnumerable<T> but rather a property on array types in .Net such as int[]. The difference is performance. TheLength property is guaranteed to be a O(1) operation. The complexity of the Count extension method … Read more

Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?

I’m not much sure what useful it really is, as I think for most cases in the Base Library expecting an IComparer there’s an overload that expects a Comparison… but just for the record: in .Net 4.5 they’ve added a method to obtain an IComparer from a Comparison: Comparer.Create so you can pass your lambda … Read more

Do I need to consider disposing of any IEnumerable I use?

No, you don’t need to worry about this. The fact that they return an IDisposable implementation is an implementation detail – it’s because iterator blocks in the Microsoft implementation of the C# compiler happen to create a single type which implements both IEnumerable<T> and IEnumerator<T>. The latter extends IDisposable, which is why you’re seeing it. … Read more