How do i get the number of elements of a dynamic object returned by Enumerable.Except()?
Look:
dynamic itensToRemove = Enumerable.Except(currentCollection, newCollection);
dynamic itensToAdd = Enumerable.Except(newCollection, currentCollection);
When i try to do this:
for (int i = 0; i < itensToRemove.Count(); i++)
I got the runtime error ‘object does not contain a definition for Count’, so, how i can i got the number of elements?
dynamicdoesn’t resolve extension methods, which is why you’ve explicitly got calls toEnumerable.Except. Do the same thing forCount:It’s not clear why you’d want to use that in a
forloop though – it would be more normal to use it in aforeachloop. You may also want to consider usingToListto make sure you evaluate the query once: