A class is a datastructure that may contain
|
An example of how you can declare a class is shown below.We will discuss about Access Modifiers, Attributes and Class-Modifiers in our later article. Access Modifiers, Attributes and Class-Modifiers are optional in a class declaration. |
[Attributes] [Access Modifiers] [Class-Modifiers] class Class-Name |
In the example below
|
using System; public class ClassDemo { //Data Members for the class const double PI = 3.14; // Constant field Declaration private int _radius; // Privta field Declaration //Instance Constructor Declaration with one parameter public ClassDemo(int Radius) { Console.WriteLine("Constructor Called"); this._radius = Radius; //The line below will generate a compile time error //PI = 486; } //Instance Method Declaration public double CalculateArea() { //Calculate the area of circle return (PI * _radius * _radius); } } public class MainClass { public static void Main() { //Create an instance of the class with new operator ClassDemo CD = new ClassDemo(10); Console.WriteLine("Area of the Circle is : " + CD.CalculateArea()); } } |
All about Constructors in a class in C# |
There are 4 different types of constructors in a class as listed below
|
Destructors in C# |
|
Learn Tips & Tricks Of Programming,Learn iPhone/iPod Programming,Learn Objective-c,Get Usefull MAC Applications
Flipkart Search
Search This Blog
Wednesday, March 18, 2009
Classes in C#
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment