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#中不是可以聲明屬性嗎?這個(gè)例子是我看的演示程序,為什么運(yùn)行不出來(lái)呢,麻煩高手給看看~~
_61.PropertyTest”不包含采用“1”參數(shù)的構(gòu)造函數(shù)
三國(guó)紛爭(zhēng)
2018-12-06 17:02:13