首页 新闻 赞助 找找看

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

0
[已解决问题] 解决于 2011-04-07 20:14

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

彼岸春秋的主页 彼岸春秋 | 初学一级 | 园豆:200
提问于:2011-04-07 19:43
< >
分享
最佳答案
0

构造需要是Public的

public PropertyTest(int age)
{
            this.age = age;
}

Chenkun | 小虾三级 |园豆:806 | 2011-04-07 19:47
谢谢~
彼岸春秋 | 园豆:200 (初学一级) | 2011-04-07 20:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册