Why does .NET foreach loop throw NullRefException when collection is null?

前端 未结 11 1865
长发绾君心
长发绾君心 2020-11-28 20:34

So I frequently run into this situation... where Do.Something(...) returns a null collection, like so:

int[] returnArray = Do.Something(...);
         


        
11条回答
  •  情深已故
    2020-11-28 21:17

    SPListItem item;
    DataRow dr = datatable.NewRow();
    
    dr["ID"] = (!Object.Equals(item["ID"], null)) ? item["ID"].ToString() : string.Empty;
    

提交回复
热议问题