接线员? [英] Operator ?

查看:72
本文介绍了接线员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释一下这个含义吗?运营商应用于我发现的
声明...


私有点? startPoint;


如果我删除了?编译器给了我一些错误,但我不明白

有什么用?在那个宣言位置......

请帮帮我

Someone can explain me the meanings of the ? operator applied to
declarations like that i found...

private Point? startPoint;

if i delete the ? the compiler gives me some errors but i don''t understand
what''s the use of ? in that declaration position...
help me please

推荐答案

2008年4月12日星期六15 :18:22 -0700,MBSoftware< mb ******** @ alice.itwrote:
On Sat, 12 Apr 2008 15:18:22 -0700, MBSoftware <mb********@alice.itwrote:

有人可以解释一下这个含义吗?运营商应用于我发现的
声明...


私有点? startPoint;


如果我删除了?编译器给了我一些错误,但我不知道
了解它的用途是什么?在该声明位置......

请帮助我
Someone can explain me the meanings of the ? operator applied to
declarations like that i found...

private Point? startPoint;

if i delete the ? the compiler gives me some errors but i don''t
understand what''s the use of ? in that declaration position...
help me please



这是Nullable< Point>的缩写。值类型变量(例如结构类似于Point的b $ b $)通常不能设置为null。但是,您可以使用

可空允许这样的版本。


你会发现它可能有点不方便,因为

回到常规值类型你必须明确地从

可空版本转换为常规版本(例如Point point =

(Point)startPoint;)。这意味着没有演员阵容,可以为空。特性
当你将值从一个变量

复制到另一个变量时,
会传播你的代码。 :)


但有时能够将值类型视为

可以为空。在这种情况下,使用可空版本只是门票。


请参阅:
http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx
http://msdn2.microsoft.com/en-us/library/2cf62fcy.aspx


此外,一个方便的运算符用于解析空值可空类型(例如,

提供默认值):
http://msdn2.microsoft.com/en-us/library/ ms173224.aspx


Pete

It''s shorthand for "Nullable<Point>". Value type variables (e.g. structs
like Point) cannot normally be set to null. However, you can use a
"nullable" version to allow that.

You''ll find that it can be a little inconvenient, due to the fact that to
get back to a regular value type you have to explicitly cast from the
nullable version to the regular version (e.g. "Point point =
(Point)startPoint;"). This means without the cast, the "nullable" trait
tends to propagate through your code as you copy values from one variable
to another. :)

But sometimes it makes sense to be able to treat a value type as
nullable. In that case, using the nullable version is just the ticket.

See:
http://msdn2.microsoft.com/en-us/library/1t3y8s4s.aspx
http://msdn2.microsoft.com/en-us/library/2cf62fcy.aspx

Also, a handy operator for resolving null-valued nullable types (e.g. to
provide a default value):
http://msdn2.microsoft.com/en-us/library/ms173224.aspx

Pete


MBSoftware写道:
MBSoftware wrote:

有人能解释一下这个含义吗?运营商应用于我发现的
声明...


私有点? startPoint;


如果我删除了?编译器给了我一些错误,但我不知道
了解它的用途是什么?在该声明位置...

请帮助我
Someone can explain me the meanings of the ? operator applied to
declarations like that i found...

private Point? startPoint;

if i delete the ? the compiler gives me some errors but i don''t
understand what''s the use of ? in that declaration position...
help me please



点是结构,因此是值类型。值类型不能是
null。通过增加 ?在声明中你使类型可以为空。这是

通常用于数据库中对应的值,这可能是

null。


我个人认为它'删除你不理解的代码并不聪明。


alain

Point is a structure and therefore a value type. Value types can not be
null. By adding ? to the declaration you make the type nullable. this is
usually used for values with a counterpart in a database which could be
null.

Personally i think it''s not smart to delete code that you don''t understand.

alain


2008年4月12日星期六15 :44:52 -0700,Alain Boss< ma ****** @ hotmail.com>

写道:
On Sat, 12 Apr 2008 15:44:52 -0700, Alain Boss <ma******@hotmail.com>
wrote:

[ ...]

我个人认为删除你不理解的代码是不明智的。
[...]
Personally i think it''s not smart to delete code that you don''t
understand.



为什么不呢?


我的意思是,你不想删除它并继续前进。但是作为尝试理解代码正在做什么的一部分(这是OP是什么,b
做什么),对代码进行更改以查看发生的情况,包括删除

它的部分内容可以看到什么休息,可以是

探索过程中非常有用的一部分。


好​​像是一个非常聪明的事情,与你自己的想法相反。

想到这件事。


当你是一个时,你没有把事情分开吗?小孩试图弄清楚

他们是如何工作的?


Pete

Why not?

I mean, you wouldn''t want to just delete it and move on. But as part of
trying to understand what the code is doing (which is what the OP was
doing), making changes to the code to see what happens, including deleting
portions of it to see what breaks, can be a very useful part of the
exploration process.

Seems like a very smart thing to do, quite the contrary to your own
thought on the matter.

Didn''t you ever take things apart when you were a kid to try to figure out
how they worked?

Pete


这篇关于接线员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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