C# class

In this chapter you will learn:

  1. What is a class
  2. How to create a class
  3. An example class

Description

Classes are essentially templates from which you can create objects.

A class is the most common kind of reference type.

Syntax

The simplest possible class declaration is as follows:


class YourClassName 
{ 
} 

The general syntax to declare a class is


[public, /*  ww  w  .ja  v  a 2s .  com*/
 internal,
 abstract, 
 sealed, 
 static, 
 unsafe, 
 partial] class YourClassName [ Generic type parameters,  a base class, and interfaces]{
     methods, 
     properties, 
     indexers, 
     events, 
     fields, 
     constructors,
     operator functions, 
     nested types, 
     a finalizer
}

Example

In the following code we define a class named Person.


class Person  
{   
} 

Next chapter...

What you will learn in the next chapter:

  1. What are C# Nested Types
  2. Example for Nested Types
  3. Note for Nested Types
  4. Accessing a private member of a type from a nested type
  5. Applying the protected access modifier to a nested type
  6. Referring to a nested type from outside the enclosing type
Home »
  C# Tutorial »
    C# Types »
      C# Class
C# class
C# Nested Types
C# Static Classes