Appendix K Classes and Structures

This appendix provides information about class and structure declarations.

Classes

The syntax for declaring a class follows.

«attributes» «accessibility» «abstract|sealed|static» «partial»
    class name «inheritance»
{
    statements
}

The following list describes the declaration’s pieces.

  • attributes—This can include any number of attribute specifiers.
  • accessibility—This can be one of public, internal, private, protected, or protected internal.
  • abstract—This keyword means you cannot create instances of the class. Instead you can make instances of derived classes.
  • sealed—This keyword means you cannot derive other classes from the class.
  • static—This keyword means you cannot derive other classes from the class or create instances of it. You invoke the members of a static class by using the class’s name instead of an instance. All members of a static class must also be declared static.
  • partial—This keyword indicates that this is only part of the class declaration and that the program may include other partial declarations for this class.
  • name—This is the name you want to give the class.
  • inheritance—This clause can include a parent class, one or more interfaces, or both a parent class and interfaces. If the declaration includes a parent class and interfaces, the parent class must come first.

Structures

The syntax for writing a structure follows.

«attributes» «accessibility» «partial» struct name «interfaces»
{
    statements
}

The structure’s attributes

Get C# 5.0 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.