02 2023 档案
摘要:1. 单一职责原则(Single Responsibility Principle)类T负责两个不同的职责:职责P1,职责P2。 using System; using System.Collections.Generic; using System.Linq; using System.Text;
阅读全文
摘要:一.new 约束 new 约束指定泛型类声明中的类型实参必须有公共的无参数构造函数。 若要使用 new 约束,则该类型不能为 抽象类型。 当泛型类创建类型的新实例时,请将 new 约束应用于类型参数,如下面的示例所示: class ItemFactory<T> where T : new() { p
阅读全文
摘要:1.声明和类型模式:类型为 T 的声明模式在表达式结果为非 NULL 且满足以下任一条件时与表达式匹配 var numbers = new int[] { 10, 20, 30 }; Console.WriteLine(GetSourceLabel(numbers)); // output: 1 v
阅读全文
摘要:示例 1:goto 在 switch 语句中的使用 class SwitchTest { static void Main() { Console.WriteLine("Coffee sizes: 1=Small 2=Medium 3=Large"); Console.Write("Please e
阅读全文