C#14在.NET 10中的更新

nameof在未定泛型(Unbound generic)中的使用

nameof的入参可以是未定泛型(Unbound generic),比如List<>。表达式的结果是List。以前,你需要给泛型指定参数类型。

cs 复制代码
Console.WriteLine("Hello, World!");

Console.WriteLine("This is a .NET 10.0 application using C# 14.0 features.");

Console.WriteLine($"List<>: {nameof(List<>)}");
Console.WriteLine($"HashSet<>: {nameof(HashSet<>)}");
Console.WriteLine($"Dictionary<,>: {nameof(Dictionary<,>)}");
Console.WriteLine($"Span<>: {nameof(Span<>)}");
Console.WriteLine($"KeyValuePair<,>: {nameof(KeyValuePair<,>)}");

输入结果如下所示。

bash 复制代码
Hello, World!
This is a .NET 10.0 application using C# 14.0 features.
List<>: List
HashSet<>: HashSet
Dictionary<,>: Dictionary
Span<>: Span
KeyValuePair<,>: KeyValuePair

参考文献

  1. C# 14 updates in .NET 10 Preview 1 - Release Notes
相关推荐
Scout-leaf11 小时前
WPF新手村教程(三)—— 路由事件
c#·wpf
用户2986985301414 小时前
程序员效率工具:Spire.Doc如何助你一键搞定Word表格排版
后端·c#·.net
mudtools2 天前
搭建一套.net下能落地的飞书考勤系统
后端·c#·.net
玩泥巴的2 天前
搭建一套.net下能落地的飞书考勤系统
c#·.net·二次开发·飞书
唐宋元明清21882 天前
.NET 本地Db数据库-技术方案选型
windows·c#
郑州光合科技余经理2 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
lindexi2 天前
dotnet DirectX 通过可等待交换链降低输入渲染延迟
c#·directx·d2d·direct2d·vortice
feifeigo1232 天前
matlab画图工具
开发语言·matlab
dustcell.2 天前
haproxy七层代理
java·开发语言·前端
norlan_jame2 天前
C-PHY与D-PHY差异
c语言·开发语言