使用继承的的方式,缺点是添加功能是,上下层都需要改变; 同时为了避免为外界透露细节; 松耦合,避免两者出现静态的联系; 有接口和实现如下: public interface ITest { void A(); void B(); }[......]继续阅读

2020年5月8日 0条评论 3976点热度 0人点赞 痴者工良 阅读全文

Using inheritance has the drawback that adding functionality requires changes in both the upper and lower layers. At the same time, it is necessary to[......] 继续阅读

2020年5月8日 0条评论 901点热度 0人点赞 痴者工良 阅读全文

静态类的构造函数不能加上访问修饰符,也不能被外界调用,也没有参数; 静态类的构造函数在创建第一个实例或调用第一个成员前触发调用; 静态类不能被继承; 而单例模式的类型,是一个普通的类型,可以被实例化,能够有多个构造函数;能够被继承; [......] 继续阅读

2020年5月7日 0条评论 4195点热度 0人点赞 痴者工良 阅读全文

The static class constructor cannot have access modifiers, cannot be called externally, and has no parameters; The static class constructor is trigge[......] 继续阅读

2020年5月7日 0条评论 1058点热度 0人点赞 痴者工良 阅读全文

假设有一段代码原本在 Windows 上运行,继承了接口 IDo,但是现在要迁移到 Linux 运行,可是某些地方不兼容,而同事已经将代码写好了,但是没有继承在 Windows 下运行的 IDo 接口,又不能改动以前的代码,必须保证都兼容。 原代码如下: // 只接受 Ido 的类型[......]继续阅读

2020年5月7日 1条评论 988点热度 0人点赞 痴者工良 阅读全文

假设有一段代码原本在 Windows 上运行,继承了接口 IDo,但是现在要迁移到 Linux 运行,可是某些地方不兼容,而同事已经将代码写好了,但是没有继承在 Windows 下运行的 IDo 接口,又不能改动以前的代码,必须保证都兼容。 原代码如下: // 只接受 Ido 的类型[......]继续阅读

2020年5月7日 1条评论 4304点热度 0人点赞 痴者工良 阅读全文

除了手动实现单例模式,也可以使用 Lazy 泛型实现单例模式。 public sealed class Singleton { private static readonly Lazy lazy = new Lazy(() => new Singleton());[......]继续阅读

2020年5月7日 0条评论 5142点热度 0人点赞 痴者工良 阅读全文

Besides manually implementing the singleton pattern, you can also use the Lazy generic type to implement the singleton pattern. public sealed clas[......]继续阅读

2020年5月7日 0条评论 1078点热度 0人点赞 痴者工良 阅读全文

工厂模式和抽象工厂模式,都是避免调用者直接 new 一个新的实例,预先将创建逻辑编写在工厂代码中,并且对实例进行和一些配置,然后分配调用者使用。 原有代码: HttpRequest 作用是检查网址是否能够访问以及健康状态。 using System; using System.Collections[......]继续阅读

2020年5月7日 0条评论 3732点热度 0人点赞 痴者工良 阅读全文

Factory Method and Abstract Factory patterns both avoid direct instantiation of new instances by the caller. Instead, they encapsulate the creation lo[......] 继续阅读

2020年5月7日 0条评论 1048点热度 0人点赞 痴者工良 阅读全文

Method 1: Add the following to the .csproj file: <ItemGroup> <RuntimeHostConfigurationOption Include="System.Globalization.Invariant[......]继续阅读

2020年4月22日 1条评论 1098点热度 3人点赞 痴者工良 阅读全文

方法一: csproj文件中,加上 方法二: .runtimeconfig.json 文件加上 { "runtimeOptions": { "configProperties": { "System.Globalization.Invariant&[......] 继续阅读

2020年4月22日 1条评论 6777点热度 3人点赞 痴者工良 阅读全文

/// <summary> /// base64转为图片存储到本地 /// </summary> /// <param name="base64"></param>[......]继续阅读

2020年4月16日 0条评论 1060点热度 0人点赞 痴者工良 阅读全文

下面是一张图片的 base64 编码 下面代码是很久前写的了,暂时不改,为了速度,请修改字符串操作部分的代码。 /// /// base64转为图片存储到本地 /// /// /// ///[......]继续阅读

2020年4月16日 0条评论 5203点热度 0人点赞 痴者工良 阅读全文

Solution: Use RandomNumberGenerator to generate random numbers. https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumberg[......] 继续阅读

2020年4月16日 0条评论 893点热度 0人点赞 痴者工良 阅读全文

解决方法: 使用 RandomNumberGenerator 来生成随机数。 https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.randomnumbergenerator?view=netcore-3.1[......] 继续阅读

2020年4月16日 0条评论 4443点热度 0人点赞 痴者工良 阅读全文

Tip: 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111[......] 继续阅读

2020年4月12日 0条评论 3070点热度 0人点赞 痴者工良 阅读全文

文章内容有知识点提示时: 提示:1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111[......] 继续阅读

2020年4月12日 0条评论 3828点热度 0人点赞 痴者工良 阅读全文

[5 Minutes] Rookie Study on Design Patterns: Six Design Principles [TOC] As a rookie, the author will attempt to explain the characteristics and appli[......] 继续阅读

2020年4月4日 0条评论 1132点热度 1人点赞 痴者工良 阅读全文

[5分钟]菜鸟修研之设计模式:六大设计原则 [TOC] 笔者作为一个菜鸟,会尝试以简单的代码和容易理解的语句去解释这几种原则的特性和应用场景。 这六种原则分别为单一职责原则、接口隔离原则、里氏替换原则、迪米特法则、依赖倒置原则、开闭原则。 单一职责原则 单一职责原则(SRP:Single respo[......] 继续阅读

2020年4月4日 0条评论 4024点热度 2人点赞 痴者工良 阅读全文
167891014