Skip to content
WJunction - Webmaster Forum

C# Basics I - Classes in C#

Status
Not open for further replies.
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.
 

9 comments

i just started learning C# eso :P
i dont think you can afford my fee <_<

---

oh btw thread updated and will keep on updating :)
 
:(( Please teach me or else die :|

Aah I know you will help me further champ.

Well good luck learning C# its very easy ;)
 
Are you gonna hate on C# for no reason in every post sniper? Tell me, what about C++ classes do you think is easier?
 
Status
Not open for further replies.

About the author

I
Active Member · Joined
1,001
Messages
18
Reactions
38
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom