What does the ? mean after a type? [duplicate]

谁说胖子不能爱 提交于 2019-12-17 20:45:23

问题


Possible Duplicate:
a curious c# syntax

So I've seen some code around and a few of them use a ? after the type, like this:

private Point? loc = null;

So I'm wondering if Point? is different than Point (can't put a question mark at the end of my sentence or I'll confuse you guys ... :] ). The language I'm using is C# by the way.


回答1:


T? is a shorthand (in C#) for Nullable<T> - so Point? is another way of writing Nullable<Point> or example.

See sections 1.3 and 4.1 of the C# 3 language spec - and various other places, to be honest - for more details. See the docs for System.Nullable<T> for more information from the framework side of things. Or read chapter 4 of C# in Depth :) (Unfortunately it's not one of the free chapters.)

(This question is bound to be a duplicate, but I don't have the energy to find it right now.)




回答2:


Point? is the same as Nullable<Point>. It allows you to assign null to value types, such as structs.




回答3:


It means the type can accept its' value and null.



来源:https://stackoverflow.com/questions/2079334/what-does-the-mean-after-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!