Solved

The name of the base class must come before any interface. Why?

Posted on 2009-07-14
3
910 Views
Last Modified: 2012-05-07
Enclosed code would give you the "Class must come first before interface" error. I understand it is a rule, but can anybody tell me what the reason behind it?
public interface ITest
    {
        int ChildCount { get; set; }
    }
 
public class Test
    {
    }  
 
public class OrderPool : ITest, Test
    {
        public int ChildCount
        {
            get;
            set;
        }     
    }

Open in new window

0
Comment
Question by:redflair
3 Comments
 
LVL 8

Expert Comment

by:rambovn
ID: 24847082
it is something like the params keyword.
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 250 total points
ID: 24847432
I'm not sure why. But on the practical side, it's easier to read that way, because a class can implement multiple interface, but can only inherit directly from 1 base class. So by 1 glance, you would already know if a class inherits from a base class. If the base class can come in the middle of interface names, it might be a little harder to read, especially if it implements many interfaces.
0
 
LVL 8

Assisted Solution

by:ppittle
ppittle earned 250 total points
ID: 24852811
Philip is on the rihgt path.  C# implements a restrictive form of polymorphism where a class can only inherit from one base class, but can implement multiple interfaces, as opposed to a language like C++ where you can inherit from multiple base classes.  The rational behind this, is you open several odd fringe cases and reap little benefits.  For example, lets say you create class ChildClass which is to inherit from BaseClass1 and BaseClass2.  Both BaseClass1 and BaseClass2 provide a custom ToString method.  So when you write "ChildClass.ToString()"  the compiler doesn't know whether to call BaseClass1.ToString() or BaseClass2.ToString(), so you would end up with some odd behavior.

To simplify the class declaration, a baseclass must be the first object folowing the semicolon.
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
System.Speech 2 27
Video Player 2017 5 22
Printing 1 51
Call Controller Action Method from ASPX 2 14
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question