Is it IEnumerable<T>
. As far as I know, the reference always points to a class instance. What instance type does the LINQ query really point to?
These operators return a Boolean value i.e. True or False when some or all elements within a sequence satisfy a specific condition.
Making a new object that is a reference type is non-trivial. LINQ would have no idea how to do it. LINQ always returns the same instances when dealing with reference types.
The All method of System. LINQ. Queryable class returns a Boolean value if all the elements of the sequence satisfy the provided condition. It returns true if all the elements satisfy the condition otherwise it returns false.
You can find it out by calling .GetType()
on your IEnumerable<T>
variable and inspecting the type in the debugger.
For different LINQ providers and even different LINQ methods, such types may or may not be different.
What matters to your code is that they all implement IEnumerable<T>
which you should work with, or IQueryable<T>
which also accepts expressions, meaning your predicates and projections will become syntax trees and may be manipulated by a LINQ provider at runtime, e.g. to be translated into SQL.
Actual classes, if this is what you're asking about, may even be compiler-generated, e.g. yield return
expression is translated to such a class.
Either way, they are usually internal and you should never, ever depend on them.
Depending on your original data source, it is either IEnumerable or IQueryable:
The result of a Linq database query is typically IQueryable<T> which is derived from IEnumerable<T>, IQueryable, and IEnumerable.
If your database query includes an OrderBy clause, the type is IOrderedQueryable<T>, being derived from IQueryable<T>
If your data source is an IEnumerable, the result type is IEnumerable<T>
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