小编Jua*_*rta的帖子

C#中的私有构造函数

我正在阅读Beginning Visual C#2012.

考虑:

using System;
using System.Collections.Generic;
using System.Text;

namespace Ch10Ex01
{
    class MyClass
    {
        public readonly string Name;
        private int intVal;

        public int Val
        {
            get { return intVal; }
            set
            {
                if (0 <= value && value <= 10)
                    intVal = value;
                else
                    throw (new ArgumentOutOfRangeException("Val", value,
                        "Val must be assigned a value between 0 and 10."));
            }
        }

        public override string ToString()
        {
            return "Name: " + Name + "\nVal: " + Val;
        } …
Run Code Online (Sandbox Code Playgroud)

c# constructor private

3
推荐指数
1
解决办法
3680
查看次数

标签 统计

c# ×1

constructor ×1

private ×1