Когда параметры передаются значением, это не имеет никакого значения при определении константы или не с точки зрения функции вызова. В основном не имеет никакого смысла объявлять передачу параметрами, передаваемыми по значению как константа
Это почти то же самое, что и в некоторых других примерах, но меньше кода:
employees.Except(employees.Join(managers, e => e.Id, m => m.EmployeeId, (e, m) => e));
Это не проще, чем сотрудники.Где (e =>! Manager.Any (m => m.EmployeeId = = e.Id)) или ваш исходный синтаксис.
/// <summary>
/// This method returns items in a set that are not in
/// another set of a different type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TOther"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <param name="items"></param>
/// <param name="other"></param>
/// <param name="getItemKey"></param>
/// <param name="getOtherKey"></param>
/// <returns></returns>
public static IEnumerable<T> Except<T, TOther, TKey>(
this IEnumerable<T> items,
IEnumerable<TOther> other,
Func<T, TKey> getItemKey,
Func<TOther, TKey> getOtherKey)
{
return from item in items
join otherItem in other on getItemKey(item)
equals getOtherKey(otherItem) into tempItems
from temp in tempItems.DefaultIfEmpty()
where ReferenceEquals(null, temp) || temp.Equals(default(TOther))
select item;
}
Я не помню, где я нашел этот метод.
Взгляните на функцию LINQ Except (). Он делает именно то, что вам нужно.
var nonmanagers = employees.Select(e => e.Id)
.Except(managers.Select(m => m.EmployeeId))
.Select(id => employees.Single(e => e.Id == id));
var nonManagers = ( from e1 in employees select e1 ).Except( from m in managers from e2 in employees where m.EmployeeId == e2.Id select e2 );