We Need to Talk About types. A Necessary Evil

It’s not evil, but close if you don’t know which build-in primitive data type you need to use. When running around in C# it’s a fundamental good idea to have a grasp about what different data type you can use.

Abstract, Art, Border, Counting, Cyclone, Education

So you need you need to hold a number of 55000? Which primitive type would you use? A byte? short? who knows? Let’s take a look at the table and find the most suitable one.

sbyte-128 to 127
byte0 to 255
short-32,768 to 32,767
ushort0 to 65,535
int-2,147,483,648 to 2,147,483,647
uint0 to 4,294,967,295
long-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
ulong0 to 18,446,744,073,709,551,615
predefined integral types

A common mistake is unsigned vs signed. When looking at all the signed range it’s going from minus to plus the value size. When you don’t care about negative values you should use an unsigned data type like ushort.

Talking about ushort, the data type to hold the number 55000 would be most effective using the ushort type.

Further research: Integral numeric types

Other interest: list to string