variable.GetValue(variable.Id) How to cast dynamically?

variable.GetValue(variable.Id) How to cast dynamically?

I have made my method, like in how to examples, to get and set variable into zenon, but I have problem vs types, if variable is not a string type.

when I use

object operatedObject = variable.GetValue(variable.Id);
result = (int)operatedObject;

even if variable value will be in range of int type in c#, value will not be read from zenon, exception throws. Data type in zenon is DINT, in C# is int (range the same). Zenon don't have same data types as in C#. If I will make that variable of type int in zenon, than I can't to set that variable in zenon (range is different as in int in c#).

May I in some way ommit that casting or do it in better way?

This is a migrated post! Originally posted on 16.11.2021 by user Oleksandr. Please be aware that information can be outdated.