Are class constructors void by default?

怎甘沉沦 提交于 2019-12-04 16:23:52

no, they are constructors, if anything, you can think of them as returning an object of the class they are from. But, they aren't normal method/functions

No Constructors implicitly return class type same as java also.

Constructors have no return type and do not return anything, it's not a method. From C# language specification 4.0:

An instance constructor is a member that implements the actions required to initialize an instance of a class. Instance constructors are declared using constructor-declarations.

attributes opt constructor-modifiers opt constructor-declarator constructor-body

A constructor is declared like a method with no return type and the same name as the containing class

There is no return type here.

Constructor is invoked through the new operator, which is the one, that returns an instance of an object.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!