标签:cti sys span value col 访问 快捷 val 多个
Public:公有属性,在类外可以随便访问。private:私有属性,在类外既不能够访问,也不能够修改。
Class1.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Class1 { // 定义私有属性 private string _name; public string Name { // 包含两个访问器 get { return _name; } set { _name = value; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // 使用类 Class1 myname = new Class1(); // 值得注意的是,单引号只能一个字符,双引号可以多个字符 myname.Name = "namejr"; Console.WriteLine("我的名字是:" + myname.Name); Console.ReadKey(); } } }
封装快捷键:Ctrl+R+E
标签:cti sys span value col 访问 快捷 val 多个
原文地址:https://www.cnblogs.com/namejr/p/10259404.html