Choosing the Right Data Type Against Casting

I'm trying to learn how to write good C # code, and I need your advice.

If I have, for example, a value without an unsigned number that is less than 255, so this value matches the type byte. But this value will not be used as a byte, but as Intfor setting the combobox index, so it will need casting.

My question is: how much do I need to worry about data types when writing good C # code? Do I need to declare this value as Intto avoid casting?

Thank you for your time.

+3
source share
7 answers

Thank you guys for your answers. I could not accept one answer, because they complement each other, so I decided to group them.

  • 32- ( ).
  • .
  • .
  • .
0

byte int , int byte, .

, byte, int, int, .

+2

int, int.

, - .

+2

( ). byte, , . . Color R,G,B byte.

- ( , int ), .

BTW int , :

comboBox.SelectedIndex = myObj.ByteProperty;
0

.

, /casting , int, . , .

0

- , , / .

ushort , , int, . ( - - , , )

0
source

With the amount of memory currently available on our computers, memory is no longer a problem when you need to choose between byte or int.

I would add that int is much easier to handle.

0
source

All Articles