Chapter 12 Quick Reference


Chapter 12 Quick Reference

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()       {      ...      }  }




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net