What is new in .NET 8 and C#12

目录

What is new in .NET 8?

.NET Aspire

Core .NET Libraries

Metrics软件度量

Networking

Extension Libraries

Garbage Collection

Reflection Improvements

Native AOT Support

NET SDK

What is new in C# 12 ?

Primary Constructors

Collection Expressions

Inline Arrays

 Optional Parameters in Lambda Expressions

ref readonly parameters

Alias Any Type

C# Top-level statements, Global usings, Pattern Matching

Top-Level Statements

Global Usings

C# Pattern Matching模式匹配

Pattern Matching

C# Pattern Matching with Switch Expressions


What is new in .NET 8?

.NET Aspire

Cloud-ready stack designed for building observable, production-ready distributed apps.

NuGet packages targeting specific cloud-native concerns, now available in preview.

云就绪堆栈,专为构建可观察、生产就绪的分布式应用程序而设计。

针对特定云原生问题的 NuGet 包,现已提供预览版。

Core .NET Libraries

Serialization enhancements, time abstraction, UTF8 improvements, methods for working with randomness, and performance-focused types like System.Numerics and System.Runtime.Intrinsics.

序列化增强功能、时间抽象、UTF8 改进、使用随机性的方法以及注重性能的类型(如 System.Numerics 和 System.Runtime.Intrinsics)。

Metrics软件度量

Attach key-value pair tags to Meter and Instrument objects, allowing for more nuanced differentiation in aggregated metric measurements.

将键值对标签附加到 Meter 和 Instrument 对象,从而在聚合指标测量中实现更细微的区分。

Networking

Support for HTTPS proxy, ensuring encrypted communication even in proxy scenarios, thus enhancing privacy and security

Extension Libraries

Options validation, LoggerMessageAttribute constructors, extended metrics, hosted lifecycle services, keyed DI services. 

Garbage Collection

On-the-fly adjustment of memory limits, a crucial feature for cloud-service scenarios where dynamic scaling is mandatory.

Reflection Improvements

Enhanced for better performance and more efficient memory usage. Function pointers also added reflection capabilities

Native AOT Support

Efficient compilation and execution, particularly beneficial for cloud-native and high-performance scenarios.

NET SDK

More robust and feature-rich, aligning with the evolving needs of modern .NET development. Enhanced dotnet publish and dotnet pack commands.

更强大、功能更丰富,符合现代 .NET 开发不断变化的需求。增强了 dotnet publish 和 dotnet pack 命令。 

What is new in C# 12 ?

Primary Constructors

Primary constructors have been extended beyond record types. Parameters are now in scope for the entire class body.

Should assigned, explicitly declared constructors must call the primary constructor using this() syntax.

主构造函数已扩展到记录类型之外。参数现在位于整个类主体的范围内。

应分配、显式声明的构造函数必须使用 this() 语法调用主构造函数。

 public class Person(string name, int age){// Name and Age are in scope for the entire class bodypublic string Name => name;public int Age => age;}

Collection Expressions

More concise syntax to create common collection values. Simplifies the way collections are initialized and manipulated.

更简洁的语法来创建通用集合值。简化了集合的初始化和操作方式。

var numbers = new List<int> { 1, 2, 3, ..otherNumbers };
var numbers = new List<int> { 1, 2, 3, ..otherNumbers };

Inline Arrays

  • Enhance performance by enabling developers to create fixed-size arrays in struct types.
  • Useful for optimizing memory layout and improving runtime performance.
 public struct Buffer{public Span<int> InlineArray => MemoryMarshal.CreateSpan(ref _array[0], 10);private int[] _array;}

 Optional Parameters in Lambda Expressions

Default values for parameters in lambda expressions. This mirrors the syntax and rules for adding default values in methods, making lambda expressions more flexible.

Func<int, int, int> add = (x, y = 1) => x + y;
Console.WriteLine(add(5)); // Outputs 6

ref readonly parameters

  • Enhances the way readonly references are passed in C#.
  • Optimizing memory usage and performance in scenarios involving large data structures.
 public void ProcessLargeData(in LargeData data){// Processing data without the risk of modifications}

Alias Any Type

● Using alias directive to include any type, not just named types.

● Creation of semantic aliases for complex types like tuples, arrays, and pointer types.

using Coordinate = System.ValueTuple<int, int>;
Coordinate location = (10, 20);

C# Top-level statements, Global usings, Pattern Matching

Top-Level Statements

Simplify the entry point of your applications. Instead of wrapping your main logic in a Main method, you can directly write the code at the top level of your file.

using System;
Console.WriteLine("Hello, World!");

Global Usings

Make namespaces available across your entire project. Instead of repeating using statements in every file, you declare them globally in one place.

//create GlobalUsing.cs
global using System;
global using System.Collections.Generic;

C# Pattern Matching模式匹配

Pattern Matching

● More expressive syntax for checking and deconstructing values in your code.

 public class Person{public string Name { get; set; }public string Title { get; set; }}Person person = new Person { Name = "Evan", Title = "Manager" };if (person is { Title: "Manager" }){Console.WriteLine($"{person.Name} is a manager.");}

C# Pattern Matching with Switch Expressions

Pattern Matching - using switch expressions to compare discrete values.

 public State PerformOperation(Operation command) =>command switch{Operation.SystemTest => RunDiagnostics(),Operation.Start => StartSystem(),Operation.Stop => StopSystem(),Operation.Reset => ResetToReady(),_ => throw new ArgumentException("Invalid enum value for command",nameof(command)),};

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/426802.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WebGL系列教程九(动画)

目录 1 前言2 绘制立方体并进行纹理映射3 动画思路4 开始绘制4.1 在顶点着色器中声明旋转矩阵4.2 获取旋转矩阵变量并进行赋值4.3 计算角度4.4 每一帧都去绘制4.5 效果4.6 完整代码 5 总结 1 前言 上一篇我们讲了WebGL中的基础语法&#xff0c;现在我们已经讲过了三维物体的绘制…

TDengine 与 SCADA 强强联合:提升工业数据管理的效率与精准

随着时序数据库&#xff08;Time Series Database&#xff09;的日益普及&#xff0c;越来越多的工业自动化控制&#xff08;工控&#xff09;人员开始认识到其强大能力。然而&#xff0c;时序数据库在传统实时数据库应用领域&#xff0c;特别是在过程监控层的推广仍面临挑战&a…

【数据结构】排序算法---冒泡排序

文章目录 1. 定义2. 算法步骤3. 动图演示4. 性质5. 算法分析6. 代码实现C语言PythonJavaCGo 结语 1. 定义 冒泡排序&#xff08;英语&#xff1a;Bubble sort&#xff09;是一种简单的排序算法。它重复地走访过要排序的数列&#xff0c;一次比较两个元素&#xff0c;如果它们的…

Android 13 固定systemUI的状态栏为黑底白字,不能被系统应用或者三方应用修改

目录 一.背景 二.思路 三.代码流程 1.colos.xml自定义颜色 2.设置状态栏的背景颜色 3.对View进行操作 ①.对Clock(状态栏左侧的数字时钟)进行操作 ②.对电池(BatteryMeterView)进行操作 4.锁屏状态栏 5.patch汇总 一.背景 客户需求将状态栏固定成黑底白字,并且不能让系…

ipython里如何用?快速查阅帮助

1、&#xff1f;用于查询函数帮助文档&#xff0c;??用于查询带源码的帮助文档 ?用于搜索内容&#xff0c;*作为通配符。

C++调用C# DLL之踩坑记录

C是非托管代码&#xff0c;C#则是托管代码&#xff0c;无法直接调用 CLR的介绍见CLR简介 MSDN提到了两种非托管-托管的交互技术&#xff1a;CLR Interop和COM Interop 后者要将C# 类库注册为COM组件&#xff0c;本文只探讨CLR&#xff0c;要通过C CLR写中间层代码 方式一&…

IDEA 通义灵码 插件使用体验

目录 前言 主要功能 演示代码 解释代码 生成单元测试 生成代码注释 生成优化建议 代码片段补全 总结 前言 自从 AI 技术开始大规模应用&#xff0c;老板就想让下面的牛马借助 AI 工具来提高编码效率&#xff0c;由于团队都没有在实际编码中深度使用过 AI 工具&#x…

Miracast/WifiDisplay开发相关的深入调研分析-android投屏实战开发

Miracast/WifiDisplay概念介绍 Miracast Miracast是由Wi-Fi联盟于2012年所制定&#xff0c;以Wi-Fi直连&#xff08;Wi-Fi Direct&#xff09;为基础的无线显示标准。支持此标准的消费性电子产品&#xff08;又称3C设备&#xff09;可透过无线方式分享视频画面&#xff0c;例如…

VirtualBox 克隆已有的虚拟机

【前提】已经存在一个CentOS 7 虚拟机 【需求】克隆出来一个虚拟机,用于本机 【操作】 1.右击已有的虚拟机 -> 选择克隆 2.给新虚拟机起个名称 以及 生成新的MAC地址 3.克隆 4.修改网络和主机名称 # 修改网络编辑以下2个文件 vi /etc/sysconfig/network-scripts/ifcfg-enp…

Java之内部类

目录 实例内部类 静态内部类 局部内部类 匿名内部类 下面将讲解实例内部类&#xff0c;静态内部类&#xff0c;局部内部类和匿名内部类。 实例内部类 实例内部类&#xff08;也称为非静态内部类&#xff09;依赖于外部类的实例。这意味着&#xff0c;要创建实例内部类的实…

Kubernetes从零到精通(12-Ingress、Gateway API)

Ingress和Gateway API都是Kubernetes中用于管理外部访问集群服务的机制&#xff0c;但它们有不同的设计理念和适用场景。它们的基本原理是通过配置规则&#xff0c;将来自外部的网络流量路由到Kubernetes集群内部的服务上。 Ingress/Gateway API和Service Ingress/Gateway API…

Qt窗口——QToolBar

文章目录 工具栏创建工具栏设置toolTip工具栏配合菜单栏工具栏浮动状态 工具栏 QToolBar工具栏是应用程序中集成各种功能实现快捷键使用的一个区域。 可以有多个&#xff0c;也可以没有。 创建工具栏 #include "mainwindow.h" #include "ui_mainwindow.h&qu…

ARM 工业边缘计算机与 C# 编程的完美融合

在工业领域&#xff0c;随着智能化和数字化的不断推进&#xff0c;ARM 工业边缘计算机凭借其出色的性能和低功耗等优势&#xff0c;逐渐成为众多应用场景的重要支撑。而 C# 编程语言的强大功能和广泛适用性&#xff0c;使其在与 ARM 工业边缘计算机的结合中展现出了巨大的潜力。…

壹嘉情,中国与世界经济文化交流的新桥梁

壹嘉情正在全球华商领域迅速崛起。作为意大利华商总会的中国分部&#xff0c;壹嘉情承载着推动两岸及全球华商深度合作、实现资源共享和互利共赢的使命。它的成立标志着意大利华商总会在全球战略布局上的重要一步&#xff0c;同时也昭示了全球化浪潮中&#xff0c;华人企业正加…

LNMP的简单安装(ubuntu)

LNMP介绍 LNMP 是一种常见的开源软件组合&#xff0c;用于搭建高效的网站服务器环境。LNMP 代表以下四个组件&#xff1a; Linux&#xff1a;操作系统。Linux 是一种稳定、可靠、安全的开源操作系统&#xff0c;常用于服务器环境&#xff0c;特别是在企业级部署中。它负责底层…

小程序——生命周期

文章目录 运行机制更新机制生命周期介绍应用级别生命周期页面级别生命周期组件生命周期生命周期两个细节补充说明总结 运行机制 用一张图简要概述一下小程序的运行机制 冷启动与热启动&#xff1a; 小程序启动可以分为两种情况&#xff0c;一种是冷启动&#xff0c;一种是热…

js 深入理解生成器

目录 概述1 . 生成器基础2. 与普通函数的区别3. 通过 yield 中断执行3.1 yield 是干嘛的&#xff1f;3.2 yield 和 return 的区别3.3 每个生成器对象作用域都是独立的3.4 yeild 的使用位置3.5 生成器对象作为可迭代对象3.6 使用 yield 实现输入和输出3.6.1 yield实现输入3.6.1 …

【JVM安装MySQL】

环境 > VMware Workstation Pro > CentOS 7 >Navicat Premium Lite > MobaXterm添加 MySQL Yum 仓库 根据操作系统在下载界面选取对应yum库进行下载 wget https://dev.mysql.com/get/mysql80-community-release-el7-9.noarch.rpm在文件下载界面安装 rpm -ivh mysq…

<<编码>> 第 14 章 反馈与触发器(3)--锁存器与触发器 示例电路

电平触发 D 型触发器 info::操作说明 鼠标单击逻辑输入切换 0|1 状态 因复位和置位不应同时处在高电平, 因此在输入处加入一个非门反向, 然后复位和置位输入合并为 数据(Data) 输入 注: 当保持位为 0 时, 数据输入无效 primary::在线交互操作链接 https://cc.xiaogd.net/?star…

Stylized Smooth Clouds 卡通风格化云朵包

下载:​​Unity资源商店链接资源下载链接 效果图: