Skip to main content

Data types

Like many programming languages, C# has its own system of data types, which is used to create variables. A data type defines the internal representation of data, the set of values an object can take, and the valid actions that can be applied to an object.

The C# language has the following basic data types:

  • bool: stores the value true or false (boolean literals).
  • int: stores an integer from -2147483648 to 2147483647 and occupies 4 bytes.
  • double: stores a floating point number from ±5.010^-324 to ±1.710^308 and occupies 8 bytes.
  • string: stores a set of Unicode characters.

Implicit typing

Previously, we explicitly specified the type of variables, for example, int x;. And the compiler at startup already knew that x stores an integer value.

However, we can also use the implicit typing model:

var hello = “Hell to World”;    //string
var c = 20; //int