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


往期版本的C#:

What is new in C# 7,8,9,10-CSDN博客

What is the new in C#11?-CSDN博客

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 body
 public 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.mfbz.cn/a/881737.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Layout 布局组件快速搭建

文章目录 设置主题样式变量封装公共布局组件封装 Logo 组件封装 Menu 菜单组件封装 Breadcrumb 面包屑组件封装 TabBar 标签栏组件封装 Main 内容区组件封装 Footer 底部组件封装 Theme 主题组件 经典布局水平布局响应式布局搭建 Layout 布局组件添加 Layout 路由配置启动项目 …

连续数组问题

目录 一题目&#xff1a; 二思路&#xff1a; 三代码&#xff1a; 一题目&#xff1a; leetcode链接&#xff1a;. - 力扣&#xff08;LeetCode&#xff09; 二思路&#xff1a; 思路&#xff1a;前缀和&#xff08;第二种&#xff09;化0为-1hash&#xff1a; 这样可以把…

SQL server学习01-SQL server环境配置

目录 一&#xff0c;手动下载及安装 microsoft .net framework 3.5 1&#xff0c;下载 2&#xff0c;安装 二&#xff0c;安装SQL server2014 1&#xff0c;下载 2&#xff0c;安装 3&#xff0c;启动SQL server服务 三&#xff0c;下载及安装Microsoft SQL Server…

高效编程的利器 Jupyter Notebook

目录 前言1. Jupyter Notebook简介1.1 功能特点1.2 使用场景 2. 不同编程工具的对比与效率提升2.1 VS Code&#xff1a;灵活且轻量的代码编辑器2.2 PyCharm&#xff1a;面向专业开发者的集成开发环境2.3 Git&#xff1a;高效协作的版本控制工具2.4 Jupyter Notebook 和 VS Code…

【AI学习笔记】初学机器学习西瓜书概要记录(一)机器学习基础知识篇

初学机器学习西瓜书的概要记录&#xff08;一&#xff09;机器学习基础知识篇(已完结) 初学机器学习西瓜书的概要记录&#xff08;二&#xff09;常用的机器学习方法篇(持续更新) 初学机器学习西瓜书的概要记录&#xff08;三&#xff09;进阶知识篇(待更) 文字公式撰写不易&am…

【爱给网-注册安全分析报告-无验证方式导致安全隐患】

前言 由于网站注册入口容易被黑客攻击&#xff0c;存在如下安全问题&#xff1a; 1. 暴力破解密码&#xff0c;造成用户信息泄露 2. 短信盗刷的安全问题&#xff0c;影响业务及导致用户投诉 3. 带来经济损失&#xff0c;尤其是后付费客户&#xff0c;风险巨大&#xff0c;造…

virtualbox中的网络模式,网络设置,固定IP

virtualbox关于网络设置的文档&#xff1a;https://www.virtualbox.org/manual/topics/networkingdetails.html#networkingdetails DHCP Dynamic Host Configuration Protocol&#xff1a;动态主机配置协议&#xff0c;是专门用来给网络中的节点分发IP地址&#xff0c;确保每…

用友U8二次开发工具KK-FULL-*****-EFWeb使用方法

1、安装: 下一步&#xff0c;下一步即可。弹出黑框不要关闭&#xff0c;让其自动执行并关闭。 2、服务配置&#xff1a; 输入服务器IP地址&#xff0c;选择U8数据源&#xff0c;输入U8用户名及账号&#xff0c;U8登录日期勾选系统日期。测试参数有效性&#xff0c;提示测试通过…

【Unity-UGUI组件拓展】| Image 组件拓展,支持FIlled和Slice功能并存

🎬【Unity-UGUI组件拓展】| Image 组件拓展,支持FIlled和Slice功能并存一、组件介绍二、组件拓展方法三、完整代码💯总结🎬 博客主页:https://xiaoy.blog.csdn.net 🎥 本文由 呆呆敲代码的小Y 原创,首发于 CSDN🙉 🎄 学习专栏推荐:Unity系统学习专栏 🌲 游戏…

esp32 wifi 联网后,用http 发送hello 用pc 浏览器查看网页

参考chatgpt Esp32可以配置为http服务器&#xff0c;可以socket编程。为了免除编写针对各种操作系统的app。完全可以用浏览器仿问esp32服务器&#xff0c;获取esp32的各种数据&#xff0c;甚至esp的音频&#xff0c;视频。也可以利用浏览器对esp进行各种操作。但esp不能主动仿…

golang学习笔记1-go程序执行流程

声明&#xff1a;本人已有C&#xff0c;C,Python基础&#xff0c;只写本人认为的重点&#xff0c;方便自己回顾。 命令行执行go程序有两种方式&#xff0c;其流程如下图 注意第一种方式会得到可执行文件&#xff0c;第二种不会。 例1 在当前目录下编译hello.go go build hel…

Matplotlib绘图基础

1、散点图 绘制散点图是数据可视化中非常常见的操作&#xff0c;它用于显示两组数据之间的关系。Matplotlib 提供了 plt.scatter() 函数&#xff0c;可以轻松绘制散点图。以下是一个基础的散点图示例代码&#xff0c;并包含了一些优化可视化呈现的技巧。 import matplotlib.p…

istio中如何使用serviceentry引入外部服务

假设需要引入一个外部服务&#xff0c;外部服务ip为10.10.102.90&#xff0c;端口为32033. 引入到istio中后&#xff0c;我想通过域名gindemo.test.ch:9090来访问这个服务。 serviceentry yaml内容如下&#xff1a; apiVersion: networking.istio.io/v1beta1 kind: ServiceEn…

53 语言模型(和之后用来训练语言模型的数据集)_by《李沐:动手学深度学习v2》pytorch版

系列文章目录 文章目录 系列文章目录理论部分使用计数来建模N元语法总结 代码读取长序列数据随机采样顺序分区 小结练习 理论部分 在上一部分中&#xff0c;我们了解了如何将文本数据映射为词元&#xff0c;以及将这些词元可以视为一系列离散的观测&#xff0c;例如单词或字符…

构建与优化自定义进程池

1. 什么是进程池&#xff1f; 简单来说&#xff0c;进程池就是预先创建固定数量的工作进程&#xff0c;通过设计任务队列或调度算法来分配任务给空闲的进程 —— 实现“负载均衡”。 2. 进程池框架设计 枚举错误返回值&#xff1a; enum {UsageError 1,ArgError,PipeError };…

基于51单片机的汽车倒车防撞报警器系统

目录 一、主要功能 二、硬件资源 三、程序编程 四、实现现象 一、主要功能 本课题基于微控制器控制器&#xff0c; 设计一款汽车倒车防撞报警器系统。 要求&#xff1a; 要求&#xff1a;1.配有距离&#xff0c; 用于把车和障碍物之间的距离信号送入控制器。 2.配有报警系…

如何安装和注册 GitLab Runner

如何安装和注册 GitLab Runner GitLab Runner 是一个用于运行 GitLab CI/CD (Continuous Integration/Continuous Deployment) 作业。它是一个与 GitLab 配合使用的应用程序&#xff0c;可以在本地或云中运行。Runner 可以执行不同类型的作业&#xff0c;例如编译代码、运行测…

传统软件应用技术的价值转换率越来越低

为什么感觉到卷&#xff1f;可能的一个原因是大家都在进步&#xff0c;用户和竞争对手也在进步&#xff0c;而自己却没有进步&#xff0c;也谈不上思维模式的改变。 我们不谈理论、不谈理想、不谈市场环境不好&#xff0c;就谈与用户接触过程的案例&#xff0c;这是最有说服力的…

传输层协议(TCP和UDP)

目录 一、UDP 1、UDPAPI 2、UDPAPI的使用 二、TCP 1、TCPAPI 2、TCP的相关特性 2.1 确认应答 2.2 超时重传 2.3 连接管理&#xff08;三次握手&#xff0c;四次挥手&#xff09; 2.4 滑动窗口 2.5 流量控制 2.6 拥塞控制 2.7 延时应答 2.8 捎带应答 2.9 面向字节…

1.3 计算机网络的分类

欢迎大家订阅【计算机网络】学习专栏&#xff0c;开启你的计算机网络学习之旅&#xff01; 文章目录 前言一、按分布范围分类二、按传输技术分类三、按拓扑结构分类四、按使用者分类五、按传输介质分类 前言 计算机网络根据不同的标准可以被分为多种类型&#xff0c;本章从分布…