我有以下情形從另一個陣列陣列數:查找和使用LINQ C#
我從一個數據源獲取記錄的集合,並將它們添加到列表
List<Entity> e = new List<Entity>();
foreach (var elm in datasource)
{
e.Add(new Entity { First = elm.First, Second = elm.Second, Third = elm.Third });
}
這給了我是這樣的:
// -> First = John, Second = Sally, Third = Ingrid
// -> First = Sally, Second = Ingrid, Third = James
// -> First = Ingrid, Second = Sally, Third = James
我有可能的值,可以是真實的和可能的值,可以是負的數組,在列表
List<string> positives = { "John", "Sally" }
List<string> negatives = { "Ingrid", "James" }
我正在尋找一個優雅的爲什麼匹配正面數量和我在通用列表e中的否定數量,按照上面的? LINQ會有這樣的可能嗎?
由於我不熟悉LINQ不知道從哪裏開始。我試過類似的東西:
var pos = e.SelectMany(s => s in positives).Count()
但是,這會引發異常。
任何幫助,將不勝感激