What parts does a C# class usually contain?
Experience Level: Junior
Tags: C#
Answer
The class contains members. There are many different kinds of members but the three most important kinds are properties, methods and constructors.
- Properties allow you to read/write data values from/to an object that is created based on the class. Properties serve as a middleman between the external code and object underlying data values.
- Methods contain code blocks that can be executed on a class or on an object that is created based on the class.
- Constructors are special methods that are executed immediately after the object is created from class. A constuctor that is calles initializes the values of the object. A constructor is a method whose name is the same as the name of its class.
Related C# job interview questions
What is a method in C# and how do you define one?
C# JuniorWhat is a constructor in C# and why would you use it?
C# JuniorWhat is a project in Visual Studio and what file extension does it have?
C# JuniorWhat is a solution in Visual Studio and what file extension does it have?
C# JuniorWhat is a difference between .cs file and class?
C# Junior