在 C# 中,`DateTime?` 类型中的 `?` 是什么? [英] In C#, what is the `?` in the type `DateTime?`

查看:52
本文介绍了在 C# 中,`DateTime?` 类型中的 `?` 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 System.DirectoryServices.AccountManagement 时遇到了一些代码

I just ran across some code while working with System.DirectoryServices.AccountManagement

public DateTime? LastLogon { get; }

什么是?在 DateTime 之后.

What is the ? after the DateTime for.

我找到了的参考资料??运算符(C# 参考),但这不是一回事.(280Z28:这是使用可空类型的正确链接.)

I found a reference for the ?? Operator (C# Reference), but it's not the same thing. (280Z28: Here is the correct link for Using Nullable Types.)

推荐答案

? 使它成为可空类型(它是 Nullable 结构的简写,是适用于所有值类型).

The ? makes it a nullable type (it's shorthand for the Nullable<T> Structure and is applicable to all value types).

可空类型 (C#)

注意:

您链接的 ?? 是完全不同的空合并运算符.

The ?? you linked to is the null coalescing operator which is completely different.

这篇关于在 C# 中,`DateTime?` 类型中的 `?` 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆