I have the following scenario:
I get a collection of records from a data source and add them to a List
List<Entity> e = new List<Entity>();
foreach (var elm in datasource)
{
e.Add(new Entity { First = elm.First, Second = elm.Second, Third = elm.Third });
}
This gives me something like:
// -> First = John, Second = Sally, Third = Ingrid
// -> First = Sally, Second = Ingrid, Third = James
// -> First = Ingrid, Second = Sally, Third = James
I have an array of possible values that can be true and possible values that can be negative, in a List
List<string> positives = { "John", "Sally" }
List<string> negatives = { "Ingrid", "James" }
I am looking for an elegant why of matching the amount of positives and the amount of negatives I have in the generic list e, as per the above? Would something like this be possible with LINQ?
As I am not familiar with LINQ have no idea where to start. I tried something like:
var pos = e.SelectMany(s => s in positives).Count()
But this throws an exception.
Any help would be greatly appreciated