C#中“?”的几种用途
原创-
第一种:三元运算(最经常用的)
用法:string a = a == "1" ? a : "2" -
第二种:可null类型修饰符 (正常int大家都知道,是不允许为null的,不过可以通过?进行修饰来让它可null)
int a = null;//报错
int? b = null;//可正常编译
-
空合并运算符
string a = null; string b = "文字"; //这里表示,如果a为null,就返回b(??左边为null则返回??右边,??左边不为null则返回??左边); string c = a ?? b;
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
上一篇:C#一维数据函数为层级计算 下一篇:Winfrom中的保存和反选
相关文章
最新文章
- Backd:用社区投票替代融资背书的创业项目发现平台,能走多远? 49分钟前
- iPhone隐私不比Android强?牛津大学研究打破苹果安全神话 50分钟前
- Show HN: Dadgpt Open Source Halloween Costume 53分钟前
- Retroviral insertions contributed to divergence of human and chimpanzee brains 55分钟前
- Implications of Large-Scale Test-Time Compute 2小时前
- UK government sets out $800M of AI security funding 2小时前
- Xbox Turns Down Netflix $500M Offer 2小时前
- Show HN: Close the UI building AI agent loop with Protoshot 2小时前
- BBC interview with Ondřej Surý, Debian/Ubuntu PHP package maintainer 3小时前
- Talking with strangers is surprisingly informative 3小时前
itfan123


