- Home /
Variable types usage
Is it needed to use short, byte, sbyte and such, for normal variables in the game like score, indexers, counters and so on? Why? When is it needed anyway?
UPDATE: Because of the circumstances I saw that I wasn't enough argumentative in my question. I know these types of variables are used when more of them are created and used most of the time. What I really want to know is when should I take a leap and change all the ints, longs, decimals and so on to shorts, bytes and so on. When I have more than 10k or 100k or less or more, in a collection, that is frequently used for calculations and so on. (developing mostly for android).
int
is totally fine to store all kinds of fixed-point numbers! But when you need less precision, have to keep an eye on memory usage or work with some kind of low-level memory representation then the shorter integral types serve you well!
Answer by BenTristem · Feb 15, 2015 at 08:17 AM
Generally speaking if you can count it (lives, cows, shots, etc) then use int, otherwise use float.
If you get anywhere near the limits of range or precision of these two, or have huge data structures that you're concerned are taking up too much memory then explore the other options listed here...
https://msdn.microsoft.com/en-us/library/s1ax56ch.aspx
... hope that helps?
Your answer
Follow this Question
Related Questions
Checking if variable is nullable type? 3 Answers
What variable type is this? 1 Answer
How can you store a reference to something that you don't know the type of yet? 2 Answers
Vector3 is a 'type' but it is used like an 'variable' (C#) 1 Answer
Expression denotes a `type', where a `variable', `value' or `method group' was expected 1 Answer