using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LeiheDuixiang
{
/// <summary>
/// 小朋友
/// </summary>
class Child
{
/*
*封装:隐藏信息并且流出信息的对外访问接口 访问修饰符:public公共的 private私有的
* 封装的快捷键: ctrl + R + E
*/
//隐藏信息,private不能在类外进行访问
private int age;
/// <summary>
/// 完成字段的对外访问接口
/// 属性,属性的名字首字母应该大写
/// </summary>
public int Age
{
get { return age; }
set {
if (value >= 3 && value <= 7)
{
age = value;
}
}
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LeiheDuixiang
{