Sunday, June 23, 2024 21:38

Table of contents >> Introduction > Variable types

Variable types

When you declare variables in your programs, you must indicate to the compiler the type and the name of the variables. There are many variable types and derivations of them. A type defines the amount of data a variable can store, and the set of operations the program can perform on those data.

C# accepts the following base types, also known as primitive types, with the exception of string, which is a derived type:

C# data types

Additional Information

There are a lot of other types extending on these variables, that are not used as much, or they are used in special cases. While it is unlikely you will be using them any time soon, you should take a look over them to familiarize yourself with their keyword names:

C# type modifiers

The u in some keywords stands for unsigned, meaning that the variable uses the sign bit to further store relevant digits, in which case it can store only positive values or 0, but in a greater range. The s in sbyte means signed byte, and, as we will later learn, a byte variable does not have a sign bit; in this case, sbyte is a byte variable that uses a sign bit. This will be further explained in a future lesson.

In the next lesson we will learn how we can give values to our variables.

The concepts explained in this lesson are also shown visually as part of the following video:

Leave a Reply

Follow the white rabbit