前言
读了C#高级编程书(第10版)清华大学出版社
系统记录(巩固)和补充一些知识和语法糖。
正文
补充干就完事了。
语法糖关键字
Partial
定义类可以在多个地方被定义,编译的时候被当做一个类来处理(用于功能的分离)。
using
- using指令
- using别名
当遇到不同命名空间下的同类名,就可以用using a = AAA.c using b = BBB.c - using语句
定义一个范围,在范围结束时处理对象。
例如:using(var a = new A()) { //Do }
this
- this代表当前类的实例对象
-
this串联构造函数
namespace Demo { public class Test { public Test() { Console.WriteLine("无参构造函数"); } // this()对应无参构造方法Test() // 先执行Test(),后执行Test(string text) public Test(string text) : this() { Console.WriteLine(text); Console.WriteLine("有参构造函数"); } } class Program { static void Main(string[] args) { try { Test test = new Test("张三"); } catch (Exception ex) { Console.WriteLine(ex); } finally { Console.ReadLine(); } } } }
- this为原始类型扩展方法
特点:1、静态类 2、静态方法 3、第一个参数据定义的是她的可扩展类型 - this索引器
$
类似String.Format();
string srt ="1";
Debug.Log($"需要解锁道具{srt}开启");
Comments | NOTHING