zoukankan      html  css  js  c++  java
  • .Net 类构造函数可以加返回值吗?如void.

    .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

  • 相关阅读:
    PAT 1059. Prime Factors
    PAT 1058. A+B in Hogwarts
    关于树状数组
    PAT 1057. Stack
    PAT 1056. Mice and Rice
    PAT 1055. The World's Richest
    PAT 1054. The Dominant Color
    fft_filter  designed to filter gridded data in an a
    matlab 1 yr oscillations
    RMVANNUAL
  • 原文地址:https://www.cnblogs.com/liuzhendong/p/2208596.html
Copyright © 2011-2022 走看看