本文介绍了C#是什么“? &QUOT;符号在放置在通用参数后面时执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 C#是什么?当它放在一个通用参数后面的符号吗 我遇到过这段代码: public static 任务< long?> GetPageLength () { // 代码 ... } 我的尝试: 谷歌搜索,但没有找到任何信息。解决方案 问号表示它不是长更多,但可以为空。 如您所知, long 变量是值类型,值类型不能包含 null - 因此您可以使用问号创建一个也可以包含null的值类型的特殊版本:Nullable Ty pes(C#编程指南)| Microsoft Docs [ ^ ] C# What does the "?" symbol do when it's placed after a generic parameterI've come across this code:public static Task<long?> GetPageLength() { // Code ...}What I have tried:Googling but didn't find any information. 解决方案 The question mark indicates it's not a long any more, but a nullable long.As you know, long variables are value types, and value types cannot contain null - so you can use the question mark to create a special version of a value type that can also contain null: Nullable Types (C# Programming Guide) | Microsoft Docs[^] 这篇关于C#是什么“? &QUOT;符号在放置在通用参数后面时执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 05:40