0

I was having a look at the IOrderedQueryable<T> interface and noticed that it inherits from IQueryable<T> but also from System.Collections.Generic.IEnumerable<T>, IQueryable and IEnumerable

public interface IOrderedQueryable<T> : 
    System.Linq.IQueryable<T>,
    System.Collections.Generic.IEnumerable<T>,
    System.Linq.IOrderedQueryable,
    System.Linq.IQueryable,
    System.Collections.IEnumerable 

My question: Since IQueryable<T> already does inherit from these other interfaces why does IOrderedQueryable have to specify/inherit from these explicitly? Why not just inherit from System.Linq.IQueryable<T> and System.Linq.IOrderedQueryable.

Obviously this question is applicable to interface inheritance in general also.

AakashM
  • 62,551
  • 17
  • 151
  • 186
alwayslearning
  • 4,493
  • 6
  • 35
  • 47
  • Side note:Could not get the C# syntax to specify generics to appear correctly while typing.The angled brackets and T get eaten up.Hence used VB syntax.Any idea how I could get the C# syntax to work? – alwayslearning Feb 04 '11 at 13:40
  • @alwayslearning: use < and > for angle brackets – Henrik Feb 04 '11 at 13:44
  • possible duplicate of [Why collections classes in C# (like ArrayList) inherit from multiple interfaces if one of these interfaces inherits from the remaining?](http://stackoverflow.com/questions/1023375/why-collections-classes-in-c-like-arraylist-inherit-from-multiple-interfaces-i) – thecoop Feb 04 '11 at 13:45
  • When you 'format as code' (either inline with backquotes, or to a whole paragraph by indenting), your angle brackets survive. See my edit. Note that the 'format as code' button the editor will do the correct things, depending on what you have currently selected – AakashM Feb 04 '11 at 13:45
  • @alwayslearning @henrik you can also just wrap them in tick marks: `. that automatically skips formatting. – Chris Pfohl Feb 04 '11 at 13:46
  • See [this question](http://stackoverflow.com/questions/4817369/why-does-does-realy-list-implements-all-of-that-interfaces-not-just-ilistt) too, with a great accepted answer. – Jeff Sternal Feb 04 '11 at 13:51

1 Answers1

0

Classes automatically inherit these 'grand parent' interfaces, so you do not have to specify them explicitly. So, given these interfaces:

interface IBase {}
interface IChild: IBase {}

Either of these are fine:

interface IGrandChild: IChild {}
interface IGrandChild: IBase, IChild {}

The documentation just lists the ancestor interfaces for convenience and clarity: "It is much more clear for the documentation to be complete all in one place than to make you search through ten different pages to find out what the full interface set is."

Community
  • 1
  • 1
Jeff Sternal
  • 47,787
  • 8
  • 93
  • 120