当前位置: 首页 > news >正文

网上代做论文的网站好微网站一键导航

网上代做论文的网站好,微网站一键导航,东莞浩智网站建设开发,室内设计学校排名模式匹配 是在 C# 7 中引入的一个非常????的特性#xff0c;你可以在任何类型上使用 模式匹配#xff0c;甚至是自定义类型#xff0c;而且在 C# 8 中得到了增强#xff0c;引入了大量的新模式类型#xff0c;这篇文章就来讨论如何在 C# 8 中使用模式匹配。C# 8 中的表… 模式匹配 是在 C# 7 中引入的一个非常????的特性你可以在任何类型上使用 模式匹配甚至是自定义类型而且在 C# 8 中得到了增强引入了大量的新模式类型这篇文章就来讨论如何在 C# 8 中使用模式匹配。C# 8 中的表达式模式 在 C# 8 中有三种不同的方式来表达这种模式。位置模式属性模式Tuple模式接下来看一下这些模式的相关代码及使用场景。位置模式位置模式主要利用类中的 Deconstruct 方法将类中的属性解构到一些零散的变量中然后实现这些零散变量的比较如果有点懵的话考虑下面的 Rectangle 类。public class Rectangle{public int Length { get; set; }public int Breadth { get; set; }public Rectangle(int x, int y)  (Length, Breadth)  (x, y);public void Deconstruct(out int x, out int y)  (x, y)  (Length, Breadth);}接下来看一下如何在 Rectangle 上使用 位置模式。static void Main(string[] args){Rectangle rectangle  new Rectangle(10, 10);var result  rectangle switch{Rectangle(0, 0)  The value of length and breadth is zero.,Rectangle(10, 10)  The value of length and breadth is same – this represents a square.,Rectangle(10, 5)  The value of length is 10, breadth is 5.,_  Default.};Console.WriteLine(result);}如果还是蒙的话继续看看最终生成的 IL 代码一目了然。 private static void Main(string[] args) {Rectangle rectangle  new Rectangle(10, 10);if (1  0){}if (rectangle  null){goto IL_0056;}rectangle.Deconstruct(out int x, out int y);string text;if (x ! 0){if (x ! 10){goto IL_0056;}if (y ! 5){if (y ! 10){goto IL_0056;}text  The value of length and breadth is same – this represents a square.;}else{text  The value of length is 10, breadth is 5.;}}else{if (y ! 0){goto IL_0056;}text  The value of length and breadth is zero.;}goto IL_005e;IL_0056:text  Default.;goto IL_005e;IL_005e:if (1  0){}string result  text;Console.WriteLine(result); }C# 8 的 属性模式属性模式常用于实现基于类中属性的比较考虑下面的 Employee 类。public class Employee{public int Id { get; set; }public string FirstName { get; set; }public string LastName { get; set; }public decimal Salary { get; set; }public string Country { get; set; }}下面的代码片段展示了如何利用 属性模式 实现 employee 的个人所得税计算。public static decimal ComputeIncomeTax(Employee employee, decimal salary)  employee switch{{ Country: Canada }  (salary * 21) / 100,{ Country: UAE }  0,{ Country: India }  (salary * 30) / 100,_  0};接下来看一下如何调用代码如下。static void Main(string[] args){Employee employee  new Employee(){Id  1,FirstName  Michael,LastName  Stevens,Salary  5000,Country  Canada};decimal incometax  ComputeIncomeTax(employee, employee.Salary);Console.WriteLine(The income tax is {0}, incometax);Console.Read();}C# 8 的 tuple模式Tuple 模式是另一种模式类型常用于实现同一时刻对多个 input 值进行测试下面的代码片段展示了如何使用 tuple模式。static void Main(string[] args){static string GetLanguageNames(string team1, string team2)  (team1, team2) switch{(C, Java)  C and Java.,(C#, Java)  C# and Java.,(C, C#)  C and C#.,(_, _)  Invalid input};(string, string, string, string) programmingLanguages  (C, Java, C#, F#);var language1  programmingLanguages.Item1.ToString();var language2  programmingLanguages.Item3.ToString();Console.WriteLine($The languages selected are: {GetLanguageNames(language1, language2)});}C# 8 中对 模式匹配进行了若干种增强使得代码写起来更加易读易维护 和 更加高效也是这么多年程序员翘首以盼的特性之一。译文链接https://www.infoworld.com/article/3518431/how-to-use-pattern-matching-in-csharp-80.html
http://www.pierceye.com/news/77309/

相关文章:

  • 福州 网站开发网站开发保密合同
  • 网站优化做些什么html简易计算器代码
  • 男子替人做网站网站wordpress 显示点击数
  • 南宁百度网站建设公司动画制作软件flash教程
  • 青岛网站建设及app聊城城乡建设局网站
  • 幕墙装饰工程网站模板小型建筑工程公司简介模板
  • 企业网站开发询问薇安徽建设行业安全协会网站
  • 仙居建设局网站桐柏微网站开发
  • 建营销型网站wordpress阅读最多插件
  • 几种语言的网站如何做网站改版的前端流程
  • 安康企业网站定制怎么样自己制作网页
  • 高端定制站开发天津网站推广优化
  • 网站开发怎么去接单湛江的高铁站建在哪里
  • 淄博网站建设找卓迅我做的网站不知道网站怎么办啊
  • qq网站 直接登录自己做的网站怎么取sql数据
  • 企业建网站的案例网站的特点
  • 怎样自己做电影网站上海seo推广价格
  • 厦门公司网页制作佛山seo关键词排名
  • 重庆网站设计软件临沂网站案例
  • ruhe用dw做网站徐州百度seo排名优化
  • seo怎样新建网站怎样才能建设只是于自己的网站
  • 北京国税局网站做票种核定时上海政务网站建设
  • 微网站地图定位陈木胜妻子
  • 网站建设网站建设的布吉商城网站建设基本流程
  • 网站seo是啥什么网站免费可以做app
  • 怎么做商务网站的架构seo规则
  • 阿里云做的网站python网页游戏开发
  • 自己做网站需要啥微商目前十大火爆产品
  • dw网站二级页面怎么做房地产开发公司网站源代码 墨绿色风格
  • 做推手需要开网站吗网站的后期运营及维护费用