我有代码:
dt = collListItems.GetDataTable().AsEnumerable()
.Where(a => Convert.ToString(a["Expertise"]).Contains(expertise) && Convert.ToString(a["Office"]) == office)
.CopyToDataTable();
filteredCount = dt.Rows.Count();
Run Code Online (Sandbox Code Playgroud)
当没有匹配的行时,我应该如何最好地处理事件?目前我得到"源包含没有DataRows"但我想在这种情况下将filteredCount设置为0.
提前致谢.
编辑:我知道try..catch有效,但有更优雅的方式吗?
假设我有一个大约50行的DataTable(SharePoint中的列表上的GetDataTable()).我想保留10个随机行,忘记其余的行.我怎样才能做到这一点?
提前致谢.
c# ×2