Classes are the blueprints for objects. Everything in C# is based upon classes.
A class normally consists of Methods, Fields and Properties. Classes are declared by using the keyword "class" followed by the class name and a set of class members surrounded by curly braces.
Example:
We define the following class:
And the result will be shown as :

A class normally consists of Methods, Fields and Properties. Classes are declared by using the keyword "class" followed by the class name and a set of class members surrounded by curly braces.
Example:
We define the following class:
//define the hand class
class Hand
{
public string name; //Field
public void ShowName() //Method
{
Console.WriteLine("My name is : " + name);
}
}
Then we use it like :Hand hand = new Hand();//Create the class object hand.name = "Left Hand";//set the field value hand.ShowName();//call the method
And the result will be shown as :

No comments :
Post a Comment
Threaded Minds would love to hear from you !!!