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
相关推荐
临床数据科学和人工智能兴趣组2 小时前
在R语言中, 使用 as.factor() 函数转换数值型变量
开发语言·r语言
andyweike5 小时前
php笔记
开发语言·笔记·php
Circ.6 小时前
Python 调试 Litellm 本地大模型接口:模型列表与对话接口实操踩坑记录
开发语言·python
波力海苔夹心脆6757 小时前
C# 序列化与反序列化详解:System.Text.Json、Newtonsoft.Json、XmlSerializer 用法、特性选项与安全实践
经验分享·后端·c#·json·.net
现任明教教主~8 小时前
Thinkphp站群蜘蛛池SaaS系统YanyvSEO含多用户/积分/六大引擎计费/易支付对接
java·开发语言·spring
Zhou1411368 小时前
SpringSecurity_02_授权与高级功能
开发语言·python
码匠许师傅8 小时前
【C++三方组件】cpp-httplib:一个头文件起 HTTP 服务
开发语言·c++·http
小小小小钰儿10 小时前
1.5-Python网络编程
开发语言·网络·python·web安全·计算机·网络安全