class1.cs

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

CS
38
字号
using System;

namespace Example_DeclareMethod
{
	/// <summary>
	/// 学生类
	/// </summary>
	public class Student
	{
		//属性		
		public string strName;	//公有属性
		private int nAge;		//私有属性		

		//方法...
		public void SetAge(int _nAge)
		{
			this.nAge=_nAge;
		}
		public int GetAge()
		{
			return this.nAge;
		}
	}

	/// <summary>
	/// Main函数类
	/// </summary>
	class Class1
	{
		static void Main(string[] args)
		{		
			Student s=new Student();
			s.SetAge(20);					//赋值年龄
			Console.WriteLine(s.GetAge());	//获取年龄
		}
	}
}

⌨️ 快捷键说明

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