foreach (DataRow row in dtcols.Rows)
{
if (!avlcols.Exists(x => x.Col开发者_StackOverflow社区Name.ToLower() == row["field_name"].ToString().ToLower()))
{
avlcols.Add(new Column()
{
ColName=row["field_name"].ToString(),
ColWidth=row["field_width"].ToString()
});
}
}
Adding only columns that dont exist in avlcols.
Change your if statment to
!avlcols.Contains(x => x.ColName.ToLower() == row["field_name"].ToString().ToLower()))
May I also Suggest using syntax like this instead
!avlcols.Contains(x => String.Equals(x.ColName, row["field_name"].ToString(), OrdinalIgnoreCase))
Replace avlCols.Exists
with avlCols.Contains
and you're there.
var rows = from row in dtcols.Cast<DataRow>()
where !avlcols.Exists(x => x.ColName.Equals(row["field_name"].ToString(),StringComparison.OrdinalIgnoreCase))
select row;
foreach(var row in rows)
{
avlcols.Add(new Column()
{
ColName = row["field_name"].ToString(),
ColWidth = row["field_width"].ToString()
});
}
精彩评论