Smartis Smartis - 25 days ago 6x
C# Question

C# Comparing Values from dynamic's

Today i tried an old project, in my company and got an error which makes me curious. The issue line looks something like this:

if((dynamic)com_list.GetIntValue() != (dynamic)container.GetEnumValue())

The exception shows clearly that you can't compare
with an

But i wonder, could this have ever worked, in some circumstance?

Are there changes in the
Keyword which don't allow this anymore?

BTW, he also build this in the code like this:

if((dynamic)com_list.GetIntValue() != (dynamic)container.GetBooleanValue())

I'm still confused, why somebody would put this kind of comparing into productiv code.


No. The dynamic specification hasn't changed and I am pretty sure the evaluation in the compiler of such a trivial comparison didn't change overnight in one release to another. Most likely that code never worked.

Without additional cast from enum to int (or the other way around) it won't work.