views:

122

answers:

1

I may not quite have my head around the IOrderedEnumerable<T> collection.

If I have a field, my_field of type IOrderedEnumerable<T>, and I wish to return it from a public property getter, can I simply return my_field;? I'm used to yielding results to an IEnumerable<T> to prevent external modification to an internally held collection, but it seems that this may not be necessary or may not even be possible in the case of an IOrderedEnumerable<T>.

Is that right?

So I couldn't declare a return type of IOrderedEnumerable<T> and yield results in an arbitrary order, such that the ordering is defined by the structure of the code rather than a property-based comparison of IComparable<T>s? Does it follow that T in an IOrderedEnumerable<T> must always implement IComparable<T>?

Are there classes in the .NET API that implement this interface, or does the type only get generated at runtime through the use of LINQ extensions?

+2  A: 

You can safely return an IOrderedEnumerable<T>; it is immutable.

It's only implemented by the internal OrderedEnumerable class in System.Linq, which is also immutable.

SLaks