日期:2014-05-17  浏览次数:20452 次

对异常的表达式赋值。。

我想用         userID=arr1["userID"].ToString()  ;如果没有的话,赋值为"";
但好像不执行  if (arr1["userID"] != null)                                                                  { 
 userID=arr1["userID"].ToString()  ;
 } 
 else
 {userID="";
}

arr1["userID"] “arr1["userID"]”引发了“System.Collections.Generic.KeyNotFoundException”类型的异常 object {System.Collections.Generic.KeyNotFoundException}

我这个情况要怎么写?

------解决方案--------------------
           if(arr1.ContainsKey("userID")&&arr1["userID"]!=null)