To |
Do this |
Create a derived class from a base class |
Declare the new class name followed by a colon and the name of the base class. For example: class Derived : Base
{
...
} |
Call a base class constructor |
Supply a constructor parameter list before the body of the derived class constructor. For example: class Derived : Base
{
...
public Derived(int x) : Base(x)
{
...
}
...
} |
Declare a virtual method |
Use the virtual keyword when declaring the method. For example: class Mammal
{
public virtual void Breathe()
{
...
}
...
} |
Declare an interface |
Use the interface keyword. For example: interface IDemo
{
string Name();
string Description();
} |
Implement an interface |
Declare a class using the same syntax as class inheritance, and then implement all the member functions of the interface. For example: class Test : IDemo
{
public string IDemo.Name()
{
...
}
public string IDemo.Description()
{
...
}
} |