-2
我有一個簡單的問題。將對象DBNULL轉換爲float.tryparse或運算符?:
場景:當用戶沒有填充場速時更新數據的方法(dt.Row [9])。
//Car.speed is float and dt.row[9] is a object
float speedo;
float.TryParse(dt.Row[9].ToString(), out speedo);
Car.speed = speedo
或
Car.speed = dt.Row[9].ToString().Equals(string.Empty) ? 0 : Convert.ToSingle(dt.Row[9])
考慮到性能和良好的代碼,什麼是更好的?任何建議?
我知道這不是什麼大不了的事情,但是我有許多具有float類型屬性的類。所以它只是讓代碼更乾淨。
的[可能的可能重複使用? (合併運算符)與DBNull?](http://stackoverflow.com/questions/9436852/possible-to-use-the-coalesce-operator-with-dbnull) – 48klocs 2014-10-17 20:43:29