静态类的构造函数不能加上访问修饰符,也不能被外界调用,也没有参数; 静态类的构造函数在创建第一个实例或调用第一个成员前触发调用; 静态类不能被继承; 而单例模式的类型,是一个普通的类型,可以被实例化,能够有多个构造函数;能够被继承; [......] 继续阅读
静态类的构造函数不能加上访问修饰符,也不能被外界调用,也没有参数; 静态类的构造函数在创建第一个实例或调用第一个成员前触发调用; 静态类不能被继承; 而单例模式的类型,是一个普通的类型,可以被实例化,能够有多个构造函数;能够被继承; [......] 继续阅读
假设有一段代码原本在 Windows 上运行,继承了接口 IDo,但是现在要迁移到 Linux 运行,可是某些地方不兼容,而同事已经将代码写好了,但是没有继承在 Windows 下运行的 IDo 接口,又不能改动以前的代码,必须保证都兼容。 原代码如下: // 只接受 Ido 的类型[......]继续阅读
除了手动实现单例模式,也可以使用 Lazy 泛型实现单例模式。 public sealed class Singleton { private static readonly Lazy lazy = new Lazy(() => new Singleton());[......]继续阅读
Besides manually implementing the singleton pattern, you can also use the Lazy generic type to implement the singleton pattern. public sealed clas[......]继续阅读
工厂模式和抽象工厂模式,都是避免调用者直接 new 一个新的实例,预先将创建逻辑编写在工厂代码中,并且对实例进行和一些配置,然后分配调用者使用。 原有代码: HttpRequest 作用是检查网址是否能够访问以及健康状态。 using System; using System.Collections[......]继续阅读
Factory Method and Abstract Factory patterns both avoid direct instantiation of new instances by the caller. Instead, they encapsulate the creation lo[......] 继续阅读
方法一: csproj文件中,加上 方法二: .runtimeconfig.json 文件加上 { "runtimeOptions": { "configProperties": { "System.Globalization.Invariant&[......] 继续阅读
Method 1: Add the following to the .csproj file: <ItemGroup> <RuntimeHostConfigurationOption Include="System.Globalization.Invariant[......]继续阅读
/// <summary> /// base64转为图片存储到本地 /// </summary> /// <param name="base64"></param>[......]继续阅读
下面是一张图片的 base64 编码 下面代码是很久前写的了,暂时不改,为了速度,请修改字符串操作部分的代码。 /// /// base64转为图片存储到本地 /// /// /// ///[......]继续阅读
Solution: Use RandomNumberGenerator to generate random numbers. https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumberg[......] 继续阅读
解决方法: 使用 RandomNumberGenerator 来生成随机数。 https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.randomnumbergenerator?view=netcore-3.1[......] 继续阅读
Tip: 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111[......] 继续阅读
文章内容有知识点提示时: 提示:1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111[......] 继续阅读
[5 Minutes] Rookie Study on Design Patterns: Six Design Principles [TOC] As a rookie, the author will attempt to explain the characteristics and appli[......] 继续阅读
[5分钟]菜鸟修研之设计模式:六大设计原则 [TOC] 笔者作为一个菜鸟,会尝试以简单的代码和容易理解的语句去解释这几种原则的特性和应用场景。 这六种原则分别为单一职责原则、接口隔离原则、里氏替换原则、迪米特法则、依赖倒置原则、开闭原则。 单一职责原则 单一职责原则(SRP:Single respo[......] 继续阅读
readonly string ganweiCosr = "AllowSpecificOrigins"; Startup.ConfigureServices 中,添加服务 #if CORS services.AddCors(options[......]继续阅读
Startup 中,添加一个变量 readonly string ganweiCosr = "AllowSpecificOrigins"; Startup.ConfigureServices 中,添加服务 #if CORS services[......]继续阅读
Create a static class to inject Dapper services. /// <summary> /// Inject Dapper /// </summary> public static class Dapper[......]继续阅读