Solved

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

Posted on 2009-07-14
3
903 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
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!
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now