You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
docs/dotnet/csharp/csharp-10/
介紹 C# 10 的新增語法和改進之處,包括:
File-scoped 命名空間 全域引用 使用 C# 檔案來管理全域引用 透過專案檔來管理全域引用 字串常數插補 巢狀屬性樣式 Lambda 語法的改進 分解式的改進 記錄的改進 以結構實作的記錄 ToString 方法可被密封 結構的改進 匿名型別的非破壞式變形 字串插補的效能改進 字串插補處理器 CallerArgumentExpression 特徵項 AsyncMethodBuilder 特徵項可套用至方法 其他改進 注意:.NET 6 或後續版本才有支援 C# 10。本章若有提及 Visual Studio,皆是指 Visual Studio 2022。
File-scoped 命名空間 C# 10 新增了 file-scoped namespace 語法,中文譯作「檔案範圍的命名空間宣告」。往後提及此語法時,大多會使用英文 file-scoped。
File-scoped 命名空間宣告只要寫一行,就可以讓整個檔案裡面的型別全都隸屬在指定的命名空間裡。光用白話解釋恐怕不好理解,看程式碼會更清楚。以往都是以一對大括號來界定一個命名空間的有效範圍,例如:
1 2 3 4 5 namespace Models { class Employee { } class Customer { } } 在 C# 10 可以這樣寫:
https://huanlin.cc/docs/dotnet/csharp/csharp-10/
Beta Was this translation helpful? Give feedback.
All reactions