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 :
![What are Classes in C# ? What are Classes in C# ?](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKbm8gRkGSuOCjHE5pK7C-WRdfjRUaEH7_SGD74Rr6eDF1eKTNrNe-rV24HVO2NdjJUxExogi-3gUMqvjylIP67az9L68GA3Kvw0ww258Zkv1EzcG62RX7CffLRTvD4QwdYEqju95nUVX/s1600/output.png)
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 :
![What are Classes in C# ? What are Classes in C# ?](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJKbm8gRkGSuOCjHE5pK7C-WRdfjRUaEH7_SGD74Rr6eDF1eKTNrNe-rV24HVO2NdjJUxExogi-3gUMqvjylIP67az9L68GA3Kvw0ww258Zkv1EzcG62RX7CffLRTvD4QwdYEqju95nUVX/s1600/output.png)
No comments :
Post a Comment
Threaded Minds would love to hear from you !!!