Solved

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

Posted on 2009-07-14
3
947 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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!
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

617 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