SlideShare a Scribd company logo
https://mvc.tw
歡迎參加我們的每週四固定聚會
1
全村的希望
一探 C# 11 與 .NET 7 的神奇
講者:Bill Chung
https://mvc.tw
about me
▪ Bill Chung
▪ 專長是說故事
▪ 海角點部落 https://dotblogs.com.tw/billchung
▪ github https://github.com/billchungiii
https://mvc.tw
Agenda
3
#
.NET
7
https://mvc.tw
Agenda
4
▪ .NET MAUI
▪ ASP.NET Core Migrations
▪ Cloud Native
▪ Performance
▪ WebSockets over HTTP/2
▪ New APIs
#
.NET
7
https://mvc.tw
.NET
7
Agenda
5
▪ String
▪ List patterns
▪ Generic attribute
▪ Generic math support
▪ Auto-default struct
▪ Extended nameof scope
▪ File-Scoped types
▪ Required members
#
https://mvc.tw
6
.NET 7 new features
https://mvc.tw
.NET MAUI
▪ 新增支援 Tizen
▪ 更多的控制項
▪ 更好的效能
https://mvc.tw
https://mvc.tw
ASP.NET Core Migrations
9
Migrate ASP.NET to ASP.NET Core
瀏覽
https://aka.ms/AspNetCoreMigration
安裝
Microsoft Project Migrations (Experimental)
Migration steps
https://mvc.tw
External
traffic
ASP.NET Business logic
External
traffic
ASP.NET Core
ASP.NET
Business logic
YARP proxy
https://mvc.tw
External
traffic
ASP.NET Core
ASP.NET
Business logic
Adapters
YARP proxy
https://mvc.tw
External
traffic
ASP.NET Core Business logic
Adapters
External
traffic
ASP.NET Core Business logic
https://mvc.tw
Installation
https://mvc.tw
Cloud Native
▪ gRPC JSON transcoding for .NET
▪ Built-in container support for the .NET SDK
▪ Azure v4 support .NET 7
https://mvc.tw
gRPC JSON transcoding for .NET
▪ Microsoft.AspNetCore.Grpc.JsonTranscoding
syntax = "proto3";
import "google/api/annotations.proto";
package greet;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {
option (google.api.http) = {
get: "/v1/greeter/{name}"
};
}
}
https://mvc.tw
built-in container support for the .NET SDK
▪ support Linux container
▪ just dotnet publish
https://mvc.tw
Performance
▪ JIT
▪ GC
▪ Native AOT
▪ Mono
▪ Reflection
▪ Interop
▪ Threading
▪ Primitive Types and Numerics
▪ Arrays, Strings, and Spans
▪ Regex
▪ Collections
▪ Regex
▪ LINQ
▪ File I/O
▪ Compression
▪ Networking
▪ JSON
▪ XML
▪ Cryptography
▪ Diagnostics
▪ Exceptions
▪ Registry
▪ Analyzers
https://mvc.tw
WebSockets over HTTP/2
class ClientWebSocket : WebSocket
{ // EXISTING
public Task ConnectAsync(Uri uri, CancellationToken cancellationToken);
// NEW
public Task ConnectAsync(Uri uri, HttpMessageInvoker invoker, CancellationToken cancellationToken);
}
class ClientWebSocketOptions
{
// NEW
public System.Version HttpVersion
{
get { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
set { }
};
public System.Net.Http.HttpVersionPolicy HttpVersionPolicy
{
get { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
set { }
};
}
https://mvc.tw
class HttpMethod : IEquatable<HttpMethod>
{
// EXISTING
// internal static HttpMethod Connect { get { throw null; } }
// NEW
public static HttpMethod Connect { get { throw null; } }
}
class HttpRequestHeaders : HttpHeaders
{
public string? Protocol { get { } set { } };
}
https://mvc.tw
Usage
ClientWebSocket ws = new();
ws.Options.HttpVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
ws.Options.HttpVersion = HttpVersion.Version20;
ws.ConnectAsync(uri, new HttpMessageInvoker(handler), cancellationToken);
HttpRequestMessage request = new(HttpMethod.Connect, server.Address);
request.Headers.Protocol = "websocket";
https://mvc.tw
APIs
▪ INumberBase<T> …
▪ Added new Tar APIs
▪ Adding Microseconds and Nanoseconds to TimeStamp,
DateTime, DateTimeOffset, and TimeOnly
https://mvc.tw
INumberBase<T>
public interface INumberBase<TSelf>
: IAdditionOperators<TSelf, TSelf, TSelf>,
IAdditiveIdentity<TSelf, TSelf>,
IDecrementOperators<TSelf>,
IDivisionOperators<TSelf, TSelf, TSelf>,
IEquatable<TSelf>,
IEqualityOperators<TSelf, TSelf, bool>,
IIncrementOperators<TSelf>,
IMultiplicativeIdentity<TSelf, TSelf>,
IMultiplyOperators<TSelf, TSelf, TSelf>,
ISpanFormattable,
ISpanParsable<TSelf>,
ISubtractionOperators<TSelf, TSelf, TSelf>,
IUnaryPlusOperators<TSelf, TSelf>,
IUnaryNegationOperators<TSelf, TSelf>
where TSelf : INumberBase<TSelf>?
https://mvc.tw
24
.C# 11 new features
https://mvc.tw
25
String
Raw string literals
UTF-8 string literals
Pattern match Span<char> or
ReadOnlySpan<char> on a constant
string
https://mvc.tw
Raw string literals
▪ 新的字串常值表示方式,使用三個雙引號 (成對)
var s = "以前你要這麼寫 "雙引號".";
var s1 = """現在你可以這麼寫 "雙引號".""";
https://mvc.tw
UTF-8 string literals
string s1 = "魯夫";
var b1 = Encoding.Unicode.GetBytes(s1);
ReadOnlySpan<byte> b2 = "魯夫"u8;
Console.WriteLine(string.Join("-", b1));
Console.WriteLine(string.Join("-", b2.ToArray ()));
var b3 = "魯夫"u8.ToArray();
https://mvc.tw
Pattern match Span
▪ 允許 Span<char> 和 ReadOnlySpan<char> 與字串常值比對
static bool Is123(ReadOnlySpan<char> s)
{
return s is "123";
}
static bool IsABC(Span<char> s)
{
return s switch { "ABC" => true, _ => false };
}
https://mvc.tw
List Patterns
▪ 清單比對模式,可以比較集合或陣列內容
int[] array = { 1,9,8,7,6,5,3};
var result = array switch
{
[1, .. var s, 3] => string.Join("-", s),
[1, 2] => "A",
[2, 5] => "B",
[1, _] => "C",
[..] => "D"
};
https://mvc.tw
Generic Attribute
public class TypeAttribute : Attribute
{
public TypeAttribute(Type t) => ParamType = t;
public Type ParamType { get; }
}
public class TypeAttribute<T> : Attribute { }
https://mvc.tw
[ServiceFilter(typeof(ResponseLoggerFilter))]
[ServiceFilter<ResponseLoggerFilter>]
Possible future
https://mvc.tw
Generic math support
static virtual members in interfaces
checked operator
https://mvc.tw
static virtual members in interfaces
public interface IMyAreaAddOperator<T> where T : IMyAreaAddOperator<T>
{
static abstract int operator + (T source ,T other);
}
public class MyRectangle : IMyAreaAddOperator<MyRectangle>
{
public int Width { get; set; }
public int Height { get; set; }
public int Area { get => Width * Height; }
public static int operator +(MyRectangle source, MyRectangle other)
{
return source.Area + other.Area;
}
}
https://mvc.tw
Generic math
public class Rectangle : IAdditionOperators<Rectangle, Rectangle, int>
{
public int Width { get; set; }
public int Height { get; set; }
public int Area { get => Width * Height; }
public static int operator +(Rectangle left, Rectangle right)
{
return left.Area + right.Area;
}
public static int operator checked+(Rectangle left, Rectangle right)
{
return left.Area + right.Area;
}
}
https://mvc.tw
Auto-default struct
public readonly struct Measurement
{
public Measurement(double value) { Value = value ;}
public Measurement(double value, string description)
{
Value = value;
Description = description;
}
public Measurement(string description)
{
// 會補上
//this.<Value>k__BackingField = 0.0;
//this.<Description>k__BackingField = "Ordinary measurement";
Description = description;
}
public double Value { get; init; }
public string Description { get; init; } = "Ordinary measurement";
public override string ToString() => $"{Value} ({Description})";
}
https://mvc.tw
Extended nameof scope
▪ nameof 敘述可用於 method 與其 parameters 的 attribute 上
[Description(nameof(Main))]
static void Main([Description(nameof(args))]string[] args)
https://mvc.tw
File-scoped types
▪ 存取修飾,限制在同一個檔案內使用的型別
file class Class1
{
public int a;
}
file class Class2
{
public Class1? c;
}
https://mvc.tw
Required members
▪ 強迫在建立執行體時,成員必須初始化
public class Person
{
[SetsRequiredMembers]
public Person(string firstName, string lastName) =>
(FirstName, LastName) = (firstName, lastName);
public required string FirstName { get; init; }
public required string LastName { get; init; }
}
Blog 是記錄知識的最佳平台
39
https://dotblogs.com.tw
40
SkillTree 為了確保內容與實務不會脫節,我們都是聘請企業顧問等級
並且目前依然在職場的業界講師,我們不把時間浪費在述說歷史與沿革,
我們並不是教您考取證照,而是教您如何上場殺敵,拳拳到肉的內容才
是您花錢想要聽到的,而這也剛好是我們擅長的。
https://skilltree.my
41
天瓏資訊圖書

More Related Content

PDF
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
PDF
twMVC#43 YARP
PPTX
Network miner 使ってみた
PDF
.NET 7 家族新成員: Microsoft Orleans v7
PDF
twMVC#44 讓我們用 k6 來進行壓測吧
PPTX
ASP.NET 開發人員不可不知的 IIS (IIS for ASP.NET Developers)
PDF
[OpenStack 스터디] OpenStack With Contrail
PDF
Realmの暗号化とAndroid System
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#43 YARP
Network miner 使ってみた
.NET 7 家族新成員: Microsoft Orleans v7
twMVC#44 讓我們用 k6 來進行壓測吧
ASP.NET 開發人員不可不知的 IIS (IIS for ASP.NET Developers)
[OpenStack 스터디] OpenStack With Contrail
Realmの暗号化とAndroid System

What's hot (20)

PPT
Systemtap
PPTX
Wiresharkの解析プラグインを作る ssmjp 201409
PDF
私たちはRESTCONFでネットワーク自動化的に何が嬉しくなるのか考えてみた
PDF
F5 BIG-IP Misconfigurations
PPTX
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 2.3.0対応)
PDF
twMVC#43 Visual Studio 2022 新功能拆解
PDF
うちのRedmineの使い方(2)
PDF
会員数180万人のマッチングサービスpairsの 急成長を支える技術基盤 ディレクターズカット版
PDF
OpenVZ - Linux Containers:第2回 コンテナ型仮想化の情報交換会@東京
PDF
フォレンジックツールの開発と実装
 
PDF
Google Maps 開始收費了該怎麼辦?
PDF
Intro to Github Actions @likecoin
PPTX
Stack pivot
PPTX
Xamarin で良くやっていたあれを MAUI でする話
PPTX
GitLab CI/CD パイプライン
PPTX
ネットワークシミュレータで手軽にネットワークのお勉強(GNS3編)
PDF
Burp suite を使って iPhone アプリを診断した時に困ったことと、解決方法
PPTX
YJTC18 A-1 データセンタネットワークの取り組み
PDF
#logstudy 01 rsyslog入門
Systemtap
Wiresharkの解析プラグインを作る ssmjp 201409
私たちはRESTCONFでネットワーク自動化的に何が嬉しくなるのか考えてみた
F5 BIG-IP Misconfigurations
FIWARE Orion Context Broker コンテキスト情報管理 (Orion 2.3.0対応)
twMVC#43 Visual Studio 2022 新功能拆解
うちのRedmineの使い方(2)
会員数180万人のマッチングサービスpairsの 急成長を支える技術基盤 ディレクターズカット版
OpenVZ - Linux Containers:第2回 コンテナ型仮想化の情報交換会@東京
フォレンジックツールの開発と実装
 
Google Maps 開始收費了該怎麼辦?
Intro to Github Actions @likecoin
Stack pivot
Xamarin で良くやっていたあれを MAUI でする話
GitLab CI/CD パイプライン
ネットワークシミュレータで手軽にネットワークのお勉強(GNS3編)
Burp suite を使って iPhone アプリを診断した時に困ったことと、解決方法
YJTC18 A-1 データセンタネットワークの取り組み
#logstudy 01 rsyslog入門
Ad

Similar to twMVC#46 一探 C# 11 與 .NET 7 的神奇 (20)

PPTX
WCF - In a Week
PDF
WebRTC 101 - How to get started building your first WebRTC application
PPTX
Windows Phone 8 - 12 Network Communication
DOCX
Laporan multi client
PDF
Netty from the trenches
PDF
Android dev 3
PPTX
Ruby on Rails vs ASP.NET MVC
PDF
Advanced #2 networking
DOC
T2
PDF
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
PPTX
SignalR
PPTX
Web sockets in Java
PDF
servlets
PDF
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
PDF
My way to clean android - Android day salamanca edition
PPTX
Retrofit 2 - O que devemos saber
PDF
Arquitecturas de microservicios - Medianet Software
PDF
Protocol-Oriented Networking
PDF
Hybrid Apps (Native + Web) using WebKit
PDF
Hybrid Apps (Native + Web) using WebKit
WCF - In a Week
WebRTC 101 - How to get started building your first WebRTC application
Windows Phone 8 - 12 Network Communication
Laporan multi client
Netty from the trenches
Android dev 3
Ruby on Rails vs ASP.NET MVC
Advanced #2 networking
T2
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
SignalR
Web sockets in Java
servlets
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
My way to clean android - Android day salamanca edition
Retrofit 2 - O que devemos saber
Arquitecturas de microservicios - Medianet Software
Protocol-Oriented Networking
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
Ad

More from twMVC (20)

PDF
twMVC#51 以平台工程重新思考系統設計 - 以 Batch System 為例封面
PDF
twMVC#51-GitHub Copilot 徹底改變開發模式,探索 AI 驅動的智慧程式碼協作
PDF
twMVC#50 微服務上線後的救贖
PDF
twMVC 47_Elastic APM 的兩三事
PDF
twMVC#44 如何測試與保護你的 web application with playwright
PDF
twMVC#43 C#10 新功能介紹
PDF
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
PDF
twMVC#42 Azure IoT Hub for Smart Factory
PDF
twMVC#42 Windows容器導入由0到1
PDF
twMVC#42 讓我們用一種方式來開發吧
PDF
twMVC#41 hololens2 MR
PPTX
twMVC#41 The journey of source generator
PDF
twMVC#38 How we migrate tfs to git(using azure dev ops)
PDF
twMVC#36C#的美麗與哀愁
PDF
twMVC#36.NetCore 3快速看一波
PDF
twMVC#36讓 Exceptionless 存管你的 Log
PDF
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
PDF
twMVC#33玩轉 Azure 彈性部署
PDF
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
PPTX
twMVC#31沒有 hdd 的網站重構 webform to mvc
twMVC#51 以平台工程重新思考系統設計 - 以 Batch System 為例封面
twMVC#51-GitHub Copilot 徹底改變開發模式,探索 AI 驅動的智慧程式碼協作
twMVC#50 微服務上線後的救贖
twMVC 47_Elastic APM 的兩三事
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#43 C#10 新功能介紹
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC#42 Azure IoT Hub for Smart Factory
twMVC#42 Windows容器導入由0到1
twMVC#42 讓我們用一種方式來開發吧
twMVC#41 hololens2 MR
twMVC#41 The journey of source generator
twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC#36C#的美麗與哀愁
twMVC#36.NetCore 3快速看一波
twMVC#36讓 Exceptionless 存管你的 Log
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33玩轉 Azure 彈性部署
twMVC#32應用 ASP.NET WebAPI2 Odata 建置高互動性 APIS
twMVC#31沒有 hdd 的網站重構 webform to mvc

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PPTX
1. Introduction to Computer Programming.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Getting Started with Data Integration: FME Form 101
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Big Data Technologies - Introduction.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
Spectroscopy.pptx food analysis technology
Digital-Transformation-Roadmap-for-Companies.pptx
Programs and apps: productivity, graphics, security and other tools
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
1. Introduction to Computer Programming.pptx
cuic standard and advanced reporting.pdf
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Dropbox Q2 2025 Financial Results & Investor Presentation
Getting Started with Data Integration: FME Form 101
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Big Data Technologies - Introduction.pptx
Spectral efficient network and resource selection model in 5G networks
20250228 LYD VKU AI Blended-Learning.pptx
SOPHOS-XG Firewall Administrator PPT.pptx

twMVC#46 一探 C# 11 與 .NET 7 的神奇