C产品在市场上有哪些独特优势?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1023个文字,预计阅读时间需要5分钟。
Intro:
在科技日新月异的今天,创新成为了推动社会进步的重要力量。伪原创作为一种创新方式,旨在在尊重原创的基础上,对已有内容进行合理改编,以新的形式呈现给读者。下面,让我们来探讨一下伪原创的几种常见方式及其内容。
C:
1. 改变句子结构:将原句的语序、句式进行调整,使其在表达上更具有新颖性。
2.替换关键词:将原文中的关键词替换为同义词或近义词,以保持原意的同时增加文章的原创性。
3.调整段落顺序:将原文中的段落顺序进行调整,使文章结构更加合理,更具可读性。
4.添加自己的观点:在改编过程中,加入自己的见解和思考,使文章更具深度和内涵。
5.简化内容:将原文中的部分内容进行简化,使文章更加简洁明了。
通过以上几种方式,我们可以将已有的内容进行伪原创改编,既保留了原文的精华,又增加了文章的新意。当然,在改编过程中,我们还需遵循原创保护的原则,尊重原作者的劳动成果。
Intro
C# 9 中进一步增强了模式匹配的用法,使得模式匹配更为强大,我们一起来了解一下吧
Sample
C# 9 中增强了模式匹配的用法,增加了 and / or / not 操作符,而且可以直接判断属性,来看一下下面的这个示例:
var person = new Person(); // or // string.IsNullOrEmpty(person.Description) if (person.Description is null or { Length: 0 }) { Console.WriteLine($"{nameof(person.Description)} is IsNullOrEmpty"); } // and // !string.IsNullOrEmpty(person.Name) if (person.Name is not null and { Length: > 0 }) { if (person.Name[0] is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z') or '.') { } } // not if (person.Name is not null) { }
这里的代码使用 DnSpy 反编译之后的代码是下面这样的:
Person person = new Person(); string text = person.Description; bool flag = text == null || text.Length == 0; if (flag) { Console.WriteLine("Description is IsNullOrEmpty"); } text = person.Name; bool flag2 = text != null && text.Length > 0; if (flag2) { char c = person.Name[0]; if (c >= 'a') { if (c > 'z') { goto IL_8B; } } else if (c >= 'A') { if (c > 'Z') { goto IL_8B; } } else if (c != ',' && c != '.') { goto IL_8B; } bool flag3 = true; goto IL_8E; IL_8B: flag3 = false; IL_8E: bool flag4 = flag3; if (flag4) { } } bool flag5 = person.Name != null; if (flag5) { }
Switch
这不仅适用于 is 也可以在 switch 中使用
switch (person.Age) { case >= 0 and <= 3: Console.WriteLine("baby"); break; case > 3 and < 14: Console.WriteLine("child"); break; case > 14 and < 22: Console.WriteLine("youth"); break; case > 22 and < 60: Console.WriteLine("Adult"); break; case >= 60 and <= 500: Console.WriteLine("Old man"); break; case > 500: Console.WriteLine("monster"); break; }
反编译后的代码:
int age = person.Age; int num = age; if (num < 22) { if (num < 14) { if (num >= 0) { if (num > 3) { Console.WriteLine("child"); } else { Console.WriteLine("baby"); } } } else if (num > 14) { Console.WriteLine("youth"); } } else if (num < 60) { if (num > 22) { Console.WriteLine("Adult"); } } else if (num > 500) { Console.WriteLine("monster"); } else { Console.WriteLine("Old man"); }
More
可以看到有些情况下可以简化不少代码,尤其是 if 分支比较多的情况下使用上面 switch 这样的写法会清晰很多
但是如果只是 string.IsNullOrEmpty 这种代码最好还是不要写得这么骚了,小心要被同事吐槽了
炫技需谨慎,小心被 ...
Reference
docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9
github.com/WeihanLi/SamplesInPractice/tree/master/CSharp9Sample
github.com/WeihanLi/SamplesInPractice/blob/master/CSharp9Sample/PatternMatchingSample.cs
到此这篇关于C#9新特性之增强的模式匹配的文章就介绍到这了,更多相关C#9 模式匹配内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!
本文共计1023个文字,预计阅读时间需要5分钟。
Intro:
在科技日新月异的今天,创新成为了推动社会进步的重要力量。伪原创作为一种创新方式,旨在在尊重原创的基础上,对已有内容进行合理改编,以新的形式呈现给读者。下面,让我们来探讨一下伪原创的几种常见方式及其内容。
C:
1. 改变句子结构:将原句的语序、句式进行调整,使其在表达上更具有新颖性。
2.替换关键词:将原文中的关键词替换为同义词或近义词,以保持原意的同时增加文章的原创性。
3.调整段落顺序:将原文中的段落顺序进行调整,使文章结构更加合理,更具可读性。
4.添加自己的观点:在改编过程中,加入自己的见解和思考,使文章更具深度和内涵。
5.简化内容:将原文中的部分内容进行简化,使文章更加简洁明了。
通过以上几种方式,我们可以将已有的内容进行伪原创改编,既保留了原文的精华,又增加了文章的新意。当然,在改编过程中,我们还需遵循原创保护的原则,尊重原作者的劳动成果。
Intro
C# 9 中进一步增强了模式匹配的用法,使得模式匹配更为强大,我们一起来了解一下吧
Sample
C# 9 中增强了模式匹配的用法,增加了 and / or / not 操作符,而且可以直接判断属性,来看一下下面的这个示例:
var person = new Person(); // or // string.IsNullOrEmpty(person.Description) if (person.Description is null or { Length: 0 }) { Console.WriteLine($"{nameof(person.Description)} is IsNullOrEmpty"); } // and // !string.IsNullOrEmpty(person.Name) if (person.Name is not null and { Length: > 0 }) { if (person.Name[0] is (>= 'a' and <= 'z') or (>= 'A' and <= 'Z') or '.') { } } // not if (person.Name is not null) { }
这里的代码使用 DnSpy 反编译之后的代码是下面这样的:
Person person = new Person(); string text = person.Description; bool flag = text == null || text.Length == 0; if (flag) { Console.WriteLine("Description is IsNullOrEmpty"); } text = person.Name; bool flag2 = text != null && text.Length > 0; if (flag2) { char c = person.Name[0]; if (c >= 'a') { if (c > 'z') { goto IL_8B; } } else if (c >= 'A') { if (c > 'Z') { goto IL_8B; } } else if (c != ',' && c != '.') { goto IL_8B; } bool flag3 = true; goto IL_8E; IL_8B: flag3 = false; IL_8E: bool flag4 = flag3; if (flag4) { } } bool flag5 = person.Name != null; if (flag5) { }
Switch
这不仅适用于 is 也可以在 switch 中使用
switch (person.Age) { case >= 0 and <= 3: Console.WriteLine("baby"); break; case > 3 and < 14: Console.WriteLine("child"); break; case > 14 and < 22: Console.WriteLine("youth"); break; case > 22 and < 60: Console.WriteLine("Adult"); break; case >= 60 and <= 500: Console.WriteLine("Old man"); break; case > 500: Console.WriteLine("monster"); break; }
反编译后的代码:
int age = person.Age; int num = age; if (num < 22) { if (num < 14) { if (num >= 0) { if (num > 3) { Console.WriteLine("child"); } else { Console.WriteLine("baby"); } } } else if (num > 14) { Console.WriteLine("youth"); } } else if (num < 60) { if (num > 22) { Console.WriteLine("Adult"); } } else if (num > 500) { Console.WriteLine("monster"); } else { Console.WriteLine("Old man"); }
More
可以看到有些情况下可以简化不少代码,尤其是 if 分支比较多的情况下使用上面 switch 这样的写法会清晰很多
但是如果只是 string.IsNullOrEmpty 这种代码最好还是不要写得这么骚了,小心要被同事吐槽了
炫技需谨慎,小心被 ...
Reference
docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9
github.com/WeihanLi/SamplesInPractice/tree/master/CSharp9Sample
github.com/WeihanLi/SamplesInPractice/blob/master/CSharp9Sample/PatternMatchingSample.cs
到此这篇关于C#9新特性之增强的模式匹配的文章就介绍到这了,更多相关C#9 模式匹配内容请搜索自由互联以前的文章或继续浏览下面的相关文章希望大家以后多多支持自由互联!

