Tuesday 24 April 2018

Calling a Base Class Constructor in C#

To call a base class constructor in a derived class in C#, define the constructor in the subclass and use the syntax :base after the signature to invoke the base class constructor.

Naming Conventions for Abstract Classes in C#

Unlike with interfaces which tend to begin with a capital I, abstract classes have no such convention in C#.

(A famous example of prefix I usage "in the field" is the ubiquitous IEnumerable in System.Collections).

Some possible conventions that can be used (though some people oppose any prefix or suffix) -
  • Prefix : Abstract
  • Suffix:  Base
On a side note, there are some facts about abstract classes in C#.

Abstract classes cannot be sealed and they cannot be private, for obvious reasons. Abstract members cannot be labelled virtual as they are implicitly virtual. Also an abstract member cannot be static - perhaps less obvious.

The internal keyword in C#

Internal types are only available in files in the same assembly (they have "assembly scope"). An example, would be an internal interface used to template for some specific classes used in the assembly.