Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-14
3
Medium Priority
?
965 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 750 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 750 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

688 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