Is using dynamic really worth?

Rashmi Jinralkar

New member
Joined
Jul 31, 2024
Messages
1
Programming Experience
10+
If the variable can contain either int or long value at runtime , should I use long to cover all cases, or use dynamic - purely from a memory consumption and performance point of view?
Note that in most of the cases it is going to have int value and only in some cases it can contain long value.
 
That doesn't seem to be a valid reason to use dynamic, which really exists to allow for late binding. more than anything. Given that the entire range of the Int32 data type can fit in an Int64 variable, there seems no reason to use anything else. dynamic would allow for any other data type too, so it's less restrictive and seems to add nothing useful, although you haven't provided much information so it's hard to know for sure.
 
purely from a memory consumption and performance point of view?

When comparing int32, int64, and dynamic, I suspect that you will find that dynamic actually uses more memory, and more [FONT=Monaco, Menlo, Consolas, Roboto Mono, Andale Mono, Ubuntu Mono, monospace]CPU.[/FONT]
 
Back
Top Bottom