Go Back   TechArena Community > ARENA > Guides & Tutorials
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 01-12-2008
Member
 
Join Date: Aug 2008
Posts: 147
Create a class in C # (CSharp)

Introduction to class CSharp

With C # everything must be contained in a class. A field, a method must therefore belong to a class. This tutorial, simple and short, aims to explain the basic rules to create and use a class.

Explanations

Hello Word

C # program must include at least one class and the class must necessarily contain the static Main method which is the entry point of the program.

Here's how the program is written minimum "Hello Word" in a console application in C #:



Create and use a class

C # can obviously contain several classes. So if you delegate the message "Hello Word" Message to a class our program becomes:


In this example of the Main method does Class Program itself over the message but called the Display method of Class Message. To do this we must first create an instance of the object by Message: Message msg = new Message ();
Reply With Quote
  #2  
Old 01-12-2008
Member
 
Join Date: Aug 2008
Posts: 147
Re: Create a class in C # (CSharp)

Create a file. Cs

Another method would be to create the class file. Cs specific.
In Visual Studio 2005 click on the Project menu / Add a class:

Naming the class:


Right in the solution explorer, a file message.c appears and Visual Studio automatically creates a vacuum that class is full of our code:
Reply With Quote
  #3  
Old 10-12-2008
Member
 
Join Date: Aug 2008
Posts: 147
Re: Create a class in C # (CSharp)

  1. Give the class a meaningful name. This name will be used as the identifier for the class when creating instances of the class or creating new subclasses. Although it is not required, C# convention calls for capitalization of the first letter in a class name.
  2. Precede the class name with the "class" keyword. The class keyword lets the compiler know that you are defining a new class and that the following code block is not a function definition. For instance: "class Vehicle"
  3. Enclose the body of the class in curly braces. The body will include any data member declarations, class methods, or nested internal classes, as demonstrated in the following example:"class Vehicle{ // data members and method definitions go here }"
  4. Precede the class keyword in the header with one of seven modifier keywords if access to the class is required. Internal is the default access for a class in C#. If no modifier is used, a class has internal access. Internal classes are only accessible from other classes in the same assembly.
Reply With Quote
Reply

  TechArena Community > ARENA > Guides & Tutorials
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Create a class in C # (CSharp)"
Thread Thread Starter Forum Replies Last Post
How to create a class in java script Lawford Software Development 5 11-02-2010 02:16 AM
How to create mouse event using Robot class in java? Luis-Fernando Software Development 4 03-02-2010 08:03 PM
How to create an inner class in java? MABON Software Development 4 01-02-2010 04:40 PM
Create own class of view in C++ tombman Software Development 3 01-05-2009 02:29 PM
How many ways to create an object for class Shanbaag Software Development 3 25-04-2009 10:08 AM


All times are GMT +5.5. The time now is 04:06 PM.