DynamicExpresso
DynamicExpresso copied to clipboard
Basic operations (+, -, *, /) between uint64 and int32 not working
Hello,
When I execute following expression, I have exception with message: "Invalid Operation". "10ul + 20" (default numeric type is int32)
Normally, uint64 and int32 types should work together. The result should be 30ul in normal conditions.
This is an interesting scenario where the compiler gives results that seem conflicting to me.
var result = 10ul + 5;
works exactly as stated in original comment.
However,
var l = 10ul;
var r = 5;
var result = l + r;
results in a compiler error saying the 'Operator "+" is ambiguous on operators of type 'ulong' and 'int''
Anybody have any insight on that?
This is actually quite strange. I suppose that in the first case the compiler is able to infer the type based on the previous number, probably this is some kind of compiler optimization where at the end only 15ul
is generated.
What is your use case? Why you need to work with ul
numbers? Just to understand if there can be alternatives ...
There are some custom functions I've included:
CustomFuncReturnsUint64() + CustomFuncReturnsInt32()
User is able to freely type a formula in my application. This is a possible case.