摘要:
new 关键字、隐藏基类方法 new 关键字还可以用来隐藏基类中的方法。 当子类的方法名称与基类中的方法名称相同,但不希望子类的方法被视为重写(override)基类的方法时,可以使用 new 关键字来声明子类的方法, 从而隐藏基类的方法。 代码示例 public class BaseClass { 阅读全文
2024年8月31日 #
摘要:
泛型中的new关键字的约束的函数 一般用于泛型约束,在函数或者类的末尾,通过 where T : new() 约束,确保 T 类型可以被实例化。 应用场景 在封装sqlsugar中我遇到了类似的用法,传给sqlsugar中的entity必须有一个公开的无参构造函数 👇👇👇👇👇👇 publ 阅读全文
摘要:
# 委托类型 事件触发 回调函数 按钮事件 DelegateButton\DelegateButton.csproj <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFrame 阅读全文
摘要:
# 委托类型 函数别名 DeleGate\Program.cs using System; class Program { // 定义一个委托类型 public delegate void OperationDelegate(int x, int y); public static void Add 阅读全文
摘要:
LearnPlayground\PubSub\Program.cs using System; // 定义一个委托类型 public delegate void MyDelegate(string message); public class Publisher { // 定义一个事件,使用前面定义 阅读全文