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

  • 相关阅读:
    #树#遍历#N叉树的前序遍历
    #树#递归#最大二叉树II
    #树#递归#二叉树的镜像
    #树#递归#最大二叉树
    #树#二叉搜索树的最近公共祖先
    #树#二叉树的直径
    #树#N叉树的后序遍历
    #树#判断平衡二叉树
    webpack+react+nodejs+express前端开发环境搭建
    sublime 玩转react+es6
  • 原文地址:https://www.cnblogs.com/liuzhendong/p/2208596.html
Copyright © 2011-2022 走看看