I am trying to learn to write good C# code and i want your advice.
If i have for example an unsigned number value that is smaller than 255 so this value fits in the byte type. But this value will not be used as byte but as an Int to set the combobox index so it will needs casting.
My question is how much do I have to worry about data types when writing good C# code? Do I need to declare this value as an Int to avoid casting?
Thank you for your time.
Casting from byte to int is safe since int is wider than byte, so no data loss is possible.
However, if you are defining a variable as byte but actually casting it to int all the time, it's better to just make it int, since you would only be confusing yourself and other readers of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With