Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Why c# do not support Multiple Inheritance

Why c# do not support Multiple Inheritance

Scheduled Pinned Locked Moved C#
csharpoop
21 Posts 11 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bernhard Hiller

    In contrast to some "experts" here on CP, I worked with a language which supports multiple inheritance: C++ (i.e. non-managed C++). Hence I think that your question is an appropriate question, it does not deserve downvoting. Let me give you an example which shows where multiple inheritance is a pain. Imagine two base classes which have a function with the same name.

    public class FirstClass
    {
    public virtual void DoSomething()
    {
    //some code
    }
    }

    and

    public class SecondClass
    {
    public virtual void DoSomething()
    {
    //some other code
    }
    }

    When you create a class inheriting from both of these classes

    public class CombinedClass: FirstClass, SecondClass
    {
    //some other code
    }

    it inherits the DoSomething() method from both FirstClass and SecondClass. When you call DoSomething() on an instance of CombinedClass

    CombinedClass c = new CombinedClass();
    c.DoSomething()

    which of the DoSomething() methods do you call - FirstClass.DoSomething() or SecondClass.DoSomething()? Other object oriented languages may offer more features which are not supported in the .Net world, e.g. inheritance of static functions and properties.

    H Offline
    H Offline
    Himanshu Yadav
    wrote on last edited by
    #21

    I like your example and way of thinking great!!!! Thanks

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups