what is the purpose of a constructor in c#
A constructor is used to initialize class objects manually or automatically. Every time an object is created, it is initialized or given initial garbage values by a default implicit constructor. However, if one is to manually create one, the initial values, too, can be user defined. (You may refer to C++ Class Constructor and Destructor) class class_name{ public: int variable_to_define; void setvariable( int var) class_name(); // This is the constructor}; class_name::class_name(void) { variable_to_define=0; //user-defined initialization }