Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define class-implementations in an interface

Tags:

c#

interface

Are you able to define class-implementations in an interface?

For instance (pseudo-code alert!)...

interface IClass1
{
    String s { get; set; }

    // classes implementing this interface has to implement Class2 as "SubClass"
    Class2 SubClass;
}

interface IClass2
{
     Int32 i { get; set; }
}

class Class1 : IClass1
{
    String IClass1.s { get; set; }

    class IClass1.Class2 SubClass
    {
        Int32 IClass2.i { get; set; }
    }
}
like image 983
cllpse Avatar asked Oct 05 '10 12:10

cllpse


1 Answers

The purpose of an interface is to define a contract which is separate from any implementation.

What you can do with an interface is defining a property like so:

interface IClass1
{
    String S { get; set; }

    Class2 SubClass { get; set; }
}
like image 154
Dirk Vollmar Avatar answered Oct 01 '22 02:10

Dirk Vollmar