Classes | C-Sharp | Dot Net Development.



A class defines the kinds of data and the functionality their objects will have. A class enables you to create your own custom types by grouping together variables of other types, methods and events.In C#, a class can be defined by using the class keyword. The data and behaviors are the members of classes we called it quantities or entities, I created a class of area to calculate the area of square and rectangle. Following are the example and syntax of writing classes in C#.



C-Sharp Data Types read here

How to create NotePad Text Editor using C-Sharp| Dot-Net Development.






Class always define inside the namespaces, in the above picture I create a class named Area and inside this class area and length are the entities of class, which is By default private access modifier, We will discuss late about Access Modifiers. Access Modifiers enables the entities of class to access outside the class, by default it is private but when you type "Public" before the datatype it will be public you can access it your program everywhere,  and then Public Area() is the constructor, what is constructor we will be discuss later, then I created two method inside the class . It is the syntax of writing class.



Now, we use this class in our Main program, how to use it let's see in below picture:


for using the class in our Main program first we create an object of class, to create an object of class syntax is :

Classname Variable = new ClassName();

e.g 
Area aa = new Area();

by doing this, object of class will be create now we use our classes in main program as I used in above program, in next post we will learn about what is Constructor and Access Modifiers. Hope You Like It , Thank You Like our Facebook page click here.


Classes | C-Sharp | Dot Net Development. Classes | C-Sharp | Dot Net Development. Reviewed by Developer Planet on October 22, 2018 Rating: 5

No comments:

Advertising

Powered by Blogger.