⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 7-4.cs

📁 java基础方面的一些实例代码
💻 CS
字号:
using System;
namespace School
{	
	public class Student
	{
		string studName;   // 默认访问修饰符是private
		int    studID;     // 默认访问修饰符是private
		string Department; // 默认访问修饰符是private
		public Student ( ) { }
		public Student(string strName)
		{   studName=strName;	}
		// 属性具有方法的本质,又具有字段的形式。
		// 定义属性类似于定义方法;使用属性类似于使用字段。
		// 用途:完善封装功能,即所有的数据成员可以设计为私有的,访问这些私有数据通过属性来访问。
		// 设计字段是为了便于内部方法使用,而尽量与外界隔绝;
		// 设计属性考虑的是方便外界的使用,但是不让外界知道的数据一律不给。
		public string StudentName
		{
			get{return studName;}   // get访问器,读取字段的值
			set{studName = value;}  // set访问器,设置字段的值,准关键字value表示输入的数据
		}
	}
	public	class Test
	{	
		static void Main(string[] args)
		{
			Student AStudent = new Student( );   // 调用默认构造函数
			AStudent.StudentName = "Li Si";      // 使用属性的set访问器
			string aName = AStudent.StudentName; // 使用属性的get访问器
			Console.WriteLine(aName);		
		}
	}
}

⌨️ 快捷键说明

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