【发布时间】:2013-02-03 16:04:35
【问题描述】:
我一直在阅读 C# 中的类构造函数。示例显示了重载的类构造函数。而且它们都没有void关键字,也没有返回值..
例如
public Class myClass
{
public myClass()
{
}
public myClass(int id)
{
}
//other class memeber go here...
}
1) 那么说 C# 构造函数默认为void 是否正确?
2) 这同样适用于 Java 吗?
【问题讨论】:
-
@mcalex 谢谢。这很有帮助 :) >根据 C# 4.0 语言规范,第 1.6 节:
Instances of classes are created using the new operator, which allocates memory for a new instance, invokes a constructor to initialize the instance, and returns a reference to the instance.
标签: c# void class-constructors