logo
  • 教程列表
  • SO官方文档
  • 空条件运算符
    • 空条件运算符
    • 空条件指数
    • 避免 NullReferenceExceptions
    • Null 条件运算符可以与扩展方法一起使用
  1. StackOverflow 文档
  2. C# Language 教程
  3. 空条件运算符
  4. 空条件指数

空条件指数

Created: November-22, 2018

与 ?. 运算符类似,null 条件索引运算符在索引到可能为 null 的集合时检查空值。

string item = collection?[index];

是语法糖

string item = null;
if(collection != null)
{
    item = collection[index];
}
  • 避免 NullReferenceExceptions
  • 空条件运算符

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明