Classes in C#

Consider the following code example, which defines a class:

Code: 
public class Hello
{
     public static void Main(string[] args)
     {
     System.Console.WriteLine("Hello, World! \n");
     }
}
The preceding class declaration provides a method Main() that will display the message Hello, World! on your screen. The parts of the preceding code need to be examined.

The Main() Function

The first line of code that a C# compiler looks for in the source file compiled is the Main() function. This function is the entry point of the application.
The Main() function is ideally used to create objects and invoke member functions.

The class Keyword

The class keyword is used to declare a class. Keywords are reserved words that have a special meaning. Here, the class keyword defines the class Hello. The braces, known as delimiters, are used to indicate the start and end of a class body.

Example:

Code: 
class Hello
     {
          ...
     }
The Class Name

The class keyword is followed by the name of the class. In the preceding example, Hello is the name of the class defined by using the class keyword. When you create classes, you must consider the following naming conventions and rules.
  • Should be meaningful (strongly recommended).
  • Should ideally be a noun.
  • Can use either the Pascal case or Camel case.




NOTE: THIS TUT IS KINDA CONTINUED IN MY NEXT TUT. Click here to view my next tut.
iFlames Reviewed by iFlames on . C# Basics I - Classes in C# Classes in C# Consider the following code example, which defines a class: public class Hello { public static void Main(string args) { System.Console.WriteLine("Hello, World! \n"); } Rating: 5