对错误的表达式赋值。

对异常的表达式赋值。。我想用userIDarr1[userID].ToString()如果没有的话,赋值为;但好像不执行if (ar

对异常的表达式赋值。。

我想用         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)