//问题一:
List<string> list = new List<string>();
list = null;
//这样写可以使用,但是当list值为null时会报未将对象的引用设置到对象的实列
if (list.Count > )
{ }
//问题2:
List<string> list2 = null;
List<string> list4 = new List<string>();
list2 = list4;
//这样写可以使用,但是当list的count为0时同样为进入到if中
if (list2 != null)
{ }
//问题三:
//这样写,当if值为null时,list.Count > 0会报未将对象的引用设置到对象的实列
if (list.Count > || list != null)
{ } //问题四:
//这样写,会报未将对象的引用设置到对象的实列
List<string> events = null;
if (events != null || events.Count != )
{ }
else
{ } //解决方法:
List<string> list3 = new List<string>();
list3 = (list3 == null) ? new List<string>() : list3;//加个这个就可以直接使用list.Count > 0这种这种判断了,list值为null也没啥影响了
if (list.Count > )
{ }
//或者
if (list3 == null || list3.Count == )
{ }
else
{ }

最新文章

  1. 从无到有实现登录功能以及thinkphp怎么配置数据库信息
  2. Azure Redis Cache
  3. [转]自己写PHP扩展之创建一个类
  4. [CC]DgmOctree—执行Cell遍历和单元计算
  5. EMC Documentum DQL整理(三)
  6. git 教程(3)--时光机穿梭
  7. 原生 js 写分页
  8. [转][LeetCode]Longest Common Prefix ——求字符串的最长公共前缀
  9. RadioButton 的background属性表现特征
  10. 局域网内Tomcat服务器没法访问
  11. CodeFirst-数据迁移-Migration
  12. 抓取锁的sql语句-第六次修改
  13. java03变量和基本数据类型
  14. iOS 7用户界面过渡指南
  15. hdu 4506 快速幂
  16. HDU5616 天平能否称出物体重量问题 01背包变形或者折半搜索
  17. [UE4]Canvas Panel
  18. 原生js返回顶部
  19. 帝国cms底部代码哪里改?要修改版权和统计代码
  20. TextBox_TextChanged

热门文章

  1. k8spod的介绍
  2. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:强调
  3. GIT使用教程——命令详解
  4. 学习笔记(4)- DQN
  5. C++ 判断是文件还是文件夹
  6. ffmpeg-01-Subtitle
  7. Python 中的else
  8. leetcode295 Find Median from Data Stream
  9. http-equiv属性的属性值X-UA-Compatible
  10. C 语言入门---第六章 C语言数组