猿问

_61.PropertyTest”不包含采用“1”参数的构造函数

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

namespace _61
{
    class PropertyTest
    {
        private int age;
        PropertyTest(int age)
        {
            this.age = age;
        }
        public int Age
        {
            get
            {
                return this.age;
            }
            set
            {
                if (value > 0 && value < 100)
                {
                    this.age = value;
                }
            }
        }
    }
    class ReadProperty
    {
        private string name;
        ReadProperty(string name)
        {
            this.name = name;
        }
        public string Name
        {
            get
            {
                return this.name;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            PropertyTest propertyTest=new PropertyTest(23);
            propertyTest.Age = 33;
            Console.WriteLine("年龄为:{0}", propertyTest.Age);
            ReadProperty readProperty=new ReadProperty("张三丰");
            Console.WriteLine("姓名为:{0}", readProperty.Name);
            Console.ReadLine();
        }
    }
}

c#中不是可以声明属性吗?这个例子是我看的演示程序,为什么运行不出来呢,麻烦高手给看看~~

三国纷争
浏览 411回答 1
1回答

哔哔one

构造需要是Public的 public PropertyTest(int age){            this.age = age;}
随时随地看视频慕课网APP
我要回答