Ryan Caputo Ryan Caputo - 1 month ago 6
C# Question

Inheritance in C# multiple properties for a single property

How would you inherit from one class and have multiples of a single property from it Example

And here is the actual code (So Far)

class NetWorkInterface
{
public double Vlan;
public string Ip;
}

class Port : NetWorkInterface
{
public double PortNumber;
}
public void test ()
{
Port newport = new Port();
newport.PortNumber = 7;
newport.Vlan = 100
}


I want to be able to add multiple interfaces to one port

Answer

I don't think you should be using inheritance here.

If you want a Port to contain a collection of NetworkInterfaces then a better definition of Port might be:

class Port
{
    public double PortNumber;
    public NetworkInterface[] networkInterfaces;
}