Why we give Constructor name same as the Class name?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Arunava BhattacharjeeRank #635 · 3.8K reputationPosted Sep 17, 2014, 7:52 PM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 18, 2014, 4:32 AM EDT
For example VB.NET uses New(), CIL uses .ctor() and Apple's new Swift language uses init().
However, C++ and Java both use the name of the class and when C# was invented the designers wanted it to feel comfortable to users of those languages. So, I guess it was an easy decision for them to do the same.
As Arunava says, it's still easy for a developer to pick out constructors from the rest of the code though perhaps not quite as easy as if they'd used the same constructor name for all classes.