Class and Object
Class in C# contains different data members and functions/methods and it binds them together. We can access the data members and functions of a class using objects of a class. Class is nothing but a blueprint of a object. You will better understand class by looking at following example.
public class Test
{
//Data Members of a class
int a, b;
public void foo()
{
// Method implementation
}
}
As shown in the above example, we have created a class called Test and to define a class we have used class keyword. The class contains two data members as a and b and one function foo. We can access those data members and function by creating object of the class. We have used public access modifier for the class so that we can access the class outside of the class. By default access modifier for a class is internal. We can create an object of the class using new keyword as shown below.
Test tst = new Test();
We can initialise the data members of the class using constructors in C#, to know more about please read my blog on constructors here.
So we have discussed about class and objects in C# today, please read my other blogs on .NET for more information.
For any issues related to C#, ASP.NET, jQuery or to provide any feedback please write to me on prson94@gmail.com, I will try my best to reply you as soon as possible.
0 comments:
Post a Comment