- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Constructors in C#
A Constructor in C# gets invoked automatically when a object gets created. The constructor has the same name as that of the class, for example −
public class Department { public Department () { Console.WriteLine("Default Constructor! "); } }
The following is the code that shows the usage of constructor in C#.
Example
using System; public class Department { public Department () { Console.WriteLine("Constructor Invoked"); } public static void Main(string[] args) { Department dept1 = new Department (); } }
Output
Constructor Invoked
- Related Articles
- Constructors in C++
- Default Constructors in C++
- Constructors in C++ Programming
- When are Constructors Called in C++?
- What are constructors in C# programs?
- Throwing exceptions from C++ constructors
- Calling virtual functions inside constructors in C++
- Private Constructors and Singleton Classes in C#
- How to implement a copy constructors in C++?
- C++ Interview questions based on constructors/ Destructors
- What is the use of static constructors in C#?
- Constructors in Java\n
- Built-in javascript constructors?
- Constructors in Dart Programming
- How to call a virtual function inside constructors in C++?

Advertisements