

- 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
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 Questions & Answers
- Constructors in Java
- Constructors in C++
- Default Constructors in C++
- Built-in javascript constructors?
- Constructors in C++ Programming
- Constructors in Dart Programming
- Get all Constructors in Java
- What are constructors in Java?
- Type of Java constructors
- PHP Constructors and Destructors
- Can interfaces have constructors in Java?
- Can constructors be inherited in Java?
- Constructors of StringBuffer class in Java.
- Constructors of StringBuilder class in Java.
- Constructors of StringTokenizer class in Java.
Advertisements