• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
金大鑫要坚持
博客园    首页    新随笔    联系   管理    订阅  订阅

【你吐吧c#每日学习】10.30 C#Nullable Types

分两种类型,value type and reference type.

By default, value type owns a default value. For integer, the default value is 0. The value type can't be null. Non nullable

But for reference types, included class, interface, delegates, arrays, objects, 这些引用类型可以=null。Nullable

? to make non nullable type nullable.

(typeName)to make nullable type non nullable(explicit conversion).

但是有时候值类型也需要等于空值呀,だから?を採用する。

bool IsMajor

bool? IsMajor=null

当一个是非的问题bool值表示用户的选择yes or no option,用户没有选择的时候

if(IsMajor==true){

}else

if(IsMajor==false) or if(!IsMajor.value){

 

}else{Console.WriteLine("User is not answer the que")}

?? Null coalescing operator

int? a=10;

int b=a??0; equals{

if(a==null){b=0;}else{b=a.Value; or b=(int)a;} //Direct Assignment will be fault. b=a

}

Double Question Mark

posted @ 2014-10-30 18:55  金大鑫要坚持  阅读(219)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3