

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is default constructor in C# programs?
A Constructor in C# is invoked automatically when an 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 default constructor in C#. The constructor invokes immediately when the object gets created −
Department dept1 = new Department ();
A default constructor is a constructor that has no argument, for example −
Department () { }
Let us see the complete example to learn how to work with default constructors −
Example
using System; public class Department { public Department () { Console.WriteLine("Constructor Invoked"); } public static void Main(string[] args) { // object Department dept1 = new Department (); } }
Output
Constructor Invoked
- Related Questions & Answers
- What is a parameterized constructor in C# programs?
- What is the default constructor in C#?
- C++ default constructor
- What is a default constructor in JavaScript?
- Default constructor in C#
- Java default constructor
- What is the purpose of a default constructor in Java?
- Default constructor in Java
- What are the differences between default constructor and parameterized constructor in Java?
- What is converting constructor in C++ ?
- What do you mean by default constructor in Java?
- What is a copy constructor in C#?
- What is a static constructor in C#?
- What are constructors in C# programs?
- What are destructors in C# programs?
Advertisements