What is Class in C#?

In this article we will explain about what is class and what is the structure of using class.
  • 3935

Class is one of the most important object oriented concept and C# is completely based on OOPs concept. Class is an encapsulated form of Data members and member functions and these functions performed operations on the data residing in the same class. All of our C# programs contains atleast one class. The Main() resides within these classes. A class is a user-defined data type. Generally, Data is hidden from the user and functions provide interface to use that data.

The following example shows the structure of using classes in C#:

class classname
{
    Data-member;
    Member-functions;
}

Here class is the keyword to declare a class. By default the access modifier of the class is internal which means that it can be used only in the application in which it is used. Here by default the members of the class whether it is data-field or functions are private which means they can't access outside the class or the application. Only the functions of the class can access its data-fields of that same class. If we want we can make them public by using access modifier public before the function name. The advantage of classes is the data hiding.

In the procedural programming the data was not secure and it can be freely flow through the function and any function can make any kind of changes on these data. So, to overcome this problem the OOPs concept was introduce and in this concept the most important concept came i.e. is class which encapsulate the data and function inside it and hide it from outside it.

Further Readings
 
You may also want to read these related articles.

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.