C# numeric types - when to use what

So… how do you decide what type to give a number when dealing with integers? Short, long, int?
I’ve seen some posts about “bits” and “bytes”? Do I need to figure how how many bits a number is before I can give it a data type? Where do I find that information? What if the number will be calculated based on a user-entered value? How do you know what the data type would be at that point? Lots of questions - sorry! I’ve purchased a textbook and tried using the Microsoft documentation but none of these resources are really answering my questions. Maybe someone can assist?

The type you would use depends on how large a value you need to store, because the main difference between the types are the range of numbers you can store:

C# type range Size
short -32,768 to 32,767 16-bit (signed)
int -2,147,483,648 to 2,147,483,647 32-bit (signed)
long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 64-bit (signed)

Source

You can use whichever you think is the best fit for the value(s) you consider acceptable; so if you want to store numbers no larger than 1,000,000 you would use int because otherwise you’re unnecessarily using memory you don’t need to - but whichever way you do it, it would be up to you to validate any input coming in before you throw it elsewhere in your program.

That is, in fact, a pretty solid rule to stick to constantly - always validate your user input!