I have a class with one property of List<String>
to hold a dynamic list of one or more string ids.
public class FieldCompareItem
{
public List<string> Fields = new List<string>();
public FieldCompareItem(string[] fields)
{
for (int i = 0; i < fields.Count(); i++)
Fields.Add(fields[i]);
}
}
}
I'm trying to compare 2 lists to see if the string arrays match but it doesn't work. Basically, I want to do an A/B compare to get items that only exist in A, in B, and in both, something like this:
var listA = new List<FieldCompareItem>
{
new FieldCompareItem(new[] {"a1"}),
new FieldCompareItem(new[] {"a2"}),
new FieldCompareItem(new[] {"a3","001"})
};
var listB = new List<FieldCompareItem>
{
new FieldCompareItem(new[] {"a2"}),
new FieldCompareItem(new[] {"a3"}),
new FieldCompareItem(new[] {"a3","001"}),
new FieldCompareItem(new[] {"a4"}),
new FieldCompareItem(new[] {"a5"})
};
//exists in A only
var aOnly = listA.Except(listB).ToList();
//expect a1,a3
//exists in B only
var bOnly = listB.Except(listA).ToList();
//expect a4,a5
//exists in both - this may be used for update A>B or B>A
var inBoth = ?????
//expect a2
Because they are values within an array property it doesnt seem to find by criteria. any help appreciated