I have an array of custom items and then I have an array of objects object[], returned by a function. This object array is indeed of the same Clients type but it is returned as array of object type (I cannot edit this aspect).
I tried with an explicit cast, but I get an exception at runtime saying: cannot convert object[] to clients[].
My goal, once I have both arrays, would be to remove from one list the items that are present in the other list too and make an union, in order to have a unique list.
var client = getClients().ToArray(); //Is an array of Clients[]
var normalSearch = getDuplicates().ToArray(); //Is an array of object[]
//This what I try to achieve,but being object, I cannot invoke "c.ContactId" (Line 4)
var uni = (from c in normalSearch
where !(from d in dupes
select d.ContactId)
.Contains(c.ContactId)
select c).ToArray();
I know that in Linq Union() could exclude automatically duplicate if a primitive type is used, otherwise an extension has to be developed with custom types. But I have not access to the rest of the code, therefore no possibility to change the logic elsewhere.
1 Answer