【发布时间】:2009-02-10 19:21:29
【问题描述】:
我使用的是 C# 2.0,我不禁认为这不是在集合(在本例中为 DataTable)搜索值的最有效方法:
bool found = false;
foreach (DataRow row in data.Rows)
{
if (id == row["rowID"])
{
found = true;
break;
}
}
if (!found)
{
//Do stuff here
}
谁能想到一种“更清洁”的方式来做到这一点?
【问题讨论】:
标签: c# search refactoring