当前位置: 代码迷 >> 综合 >> 当属性中的set什么语句都没的时候
  详细解决方案

当属性中的set什么语句都没的时候

热度:76   发布时间:2024-01-17 03:35:53.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassStudy
{
class Program
{
static void Main(string[] args)
{
Person xiaoMing = new Person();
// 当属性中的set什么语句都没的时候
xiaoMing.Age = 19;
xiaoMing.Age = xiaoMing.Age + 2;// xiaoMing.Age = 5
Console.WriteLine(xiaoMing.Age);// 3
Console.ReadKey();
}
}
class Person
{
private int age;
public int Age// 属性
{
set
{
}
get
{
return 3;
}
}
}
}


  相关解决方案