.Net 类构造函数可以加返回值吗?如void.
代码如下:
public class ReportColumn
{
public string ColumnDataField { set; get; }
public string ColumnHeaderText { set; get; }
public string ColumnSortExpression { set; get; }
public int ColumnIndex { set; get; }
public void ReportColumn(string _ColumnDataField, string _ColumnHeaderText, string _ColumnSortExpression, int _ColumnIndex)
{
this.ColumnDataField = _ColumnDataField;
this.ColumnHeaderText = _ColumnHeaderText;
this.ColumnSortExpression = _ColumnSortExpression;
this.ColumnIndex = _ColumnIndex;
}
}
有了这个void返回值,类对象在初始化时,就出毛病了,如想输入下面的代码,会报出找不到一个有这样四个参数的方法:
ReportColumn col = new ReportColumn("name", "姓名", "姓名", 1)
去掉它就可以了.
可见,构造函数不能写返回值。
***************************************************
2011/12/5 其实, 编译时就会过不去, 会提示: 'ReportColumn': member names cannot be the same as their enclosing type