class1.cs

来自「C#2005 实例源代码」· CS 代码 · 共 35 行

CS
35
字号
using System;

namespace Example_GetAndSet
{
	/// <summary>
	/// 学生类
	/// </summary>
	public class Student
	{		
		private int nAge;	//私有域
		public int Age		//属性,用户控制对域的访问
		{
			get
			{
				return this.nAge;
			}
			set
			{
				if(value!=this.nAge)
					this.nAge=value;
			}
		}
	
		/// <summary>
		/// 主函数
		/// </summary>
		static void Main(string[] args)
		{		
			Student s=new Student();
			s.Age=20;
			Console.WriteLine(s.Age);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?