鑑於以下兩種情況,哪一種更可取(如果它們都不好,那麼採用完全不同的方式也是一種選擇)?轉換不好?
Convert.ToInt32
稱爲Where
:
var items = GetItems();
if (aDropDownList.SelectedIndex > 0)
{
items = items.Where(x =>
x.IntProperty == Convert.ToInt32(aDropDownList.SelectedValue));
}
Convert.ToInt32
調用之前Where
:
var items = GetItems();
if (aDropDownList.SelectedIndex > 0)
{
int selectedDropDownValue = Convert.ToInt32(aDropDownList.SelectedValue);
items = items.Where(x => x.IntProperty == selectedDropDownValue);
}
順便說一句,只要調用'Where'就很少,除非你得到結果。 – 2010-01-26 17:45:40
我認爲你只需要在文本和代碼段之間增加一個換行符。 – Brandon 2010-01-26 17:45:58
@Marc,添加了「Where()」結果的賦值。 – jball 2010-01-26 18:01:55