本文介绍了C#2005中的可空值类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我刚看了一篇关于使用可空值类型的文章。 (值 类型可以有效地没有价值而且没有设置)。 语法是在值中添加一个问号标记 声明,例如: int?年龄; 我不喜欢那么多,我认为使用 新关键字会更加一致,例如可空 ;。但无论如何... 对于实际安装了测试版的人来说,有几个问题: 1.什么是开销声明您的值类型可以为空? 2.它们是否与非可空值类型兼容? (即我可以将 分配给另一个吗?)。 谢谢, JohnI was just looking at an article about using nullable value types. (valuetypes that can effectively have no value and not be set).The syntax is to append a question-mark to the value type in thedeclaration, eg:int? age;I don''t like that much, I think it would be much more consistent to use anew keyword, such as "nullable". But anyways...A couple of questions for anyone who actually has the beta installed:1. What''s the overhead of declaring your value types nullable?2. Are they type-compatible with non-nullable value types? (ie. can I assignone to the other?).Thanks,John推荐答案 从int到int?有一个隐含的转换。 在另一个方向是明确的(即你需要强制转换),因为它可能会导致失败(即int?can)是null这是int无法处理的值。 类型转换故事还有很多可以为nullable的类型,但是 ''除非你有一些特定的问题,否则你可能已经足够了。 MarkFrom int to int? there is an implicit conversion.In the other direction is it explicit (i.e. you need to cast) since it mightfail (i.e. the int? could be null which is a value the int cannot handle).There is a lot more to the type conversion story with nullable types, butthat''s probably enough for the moment unless you have some specific questionin mind.Mark 这篇关于C#2005中的可空值类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 02:40
查看更多