在数组的基础上过滤DataTable

pal*_*hta 1 c# linq

我有一个DataTable dtEmployee,其中一列是EmployeeId.

我有一个整数数组.我必须找到数组的所有值,这些值不在DataTable的EmployeeId列中. dtEmployee

Hab*_*bib 5

您可以使用Enumerable.Except

List<int> empIds = new List<int>(); //your employee Ids List

List<int> resultList = empIds.Except(dtEmployee .AsEnumerable()
                                       .Select(r => r.Field<int>("EmployeeID"))
                                       .ToList()).ToList();
Run Code Online (Sandbox Code Playgroud)