Home > Back-end >  Hierarchy in Interfaces (.NET Framework 4.8)
Hierarchy in Interfaces (.NET Framework 4.8)

Time:01-01

I have this two interfaces:

internal interface ClassType
    {
        string name { get; set; }
    }

internal interface ClassTexture
    {
        string texture { get; set; }
    }

I'm currently using them in seperate mainly for Where T : interface

But every class with texture has a name. Is there a way to merge them?

CodePudding user response:

Sure, interfaces may inherit from each other, like classes.

internal interface ClassTexture : ClassType
{
   string Texture { get; set; }
}

Note that by convention, property names should start with a capital letter.

Unlike with classes, there's no limit as to how many interfaces an interface (or a class!) may inherit from.

CodePudding user response:

Alternatively an implementation may list multiple interfaces.

class MyClass : ClassTexture, ClassType
{
    string Name {get;set;}
    string Texture {get;set;}
}
  •  Tags:  
  • c#
  • Related