博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
.Net 类构造函数可以加返回值吗?如void.
阅读量:7070 次
发布时间:2019-06-28

本文共 824 字,大约阅读时间需要 2 分钟。

.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

转载地址:http://xihll.baihongyu.com/

你可能感兴趣的文章