Results 1 to 3 of 3

Thread: Create a class in C # (CSharp)

  1. #1
    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 ();

  2. #2
    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:

  3. #3
    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.

Similar Threads

  1. How to create a class in java script
    By Lawford in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 02:16 AM
  2. How to create mouse event using Robot class in java?
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 03-02-2010, 08:03 PM
  3. How to create an inner class in java?
    By MABON in forum Software Development
    Replies: 4
    Last Post: 01-02-2010, 04:40 PM
  4. Create own class of view in C++
    By tombman in forum Software Development
    Replies: 3
    Last Post: 01-05-2009, 02:29 PM
  5. How many ways to create an object for class
    By Shanbaag in forum Software Development
    Replies: 3
    Last Post: 25-04-2009, 10:08 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,060,681.72989 seconds with 16 queries