Variable Types

This lesson gives an overview of all the types of variables in C# like int, bool, double, char and float and much more!

Integer

An integer is a number that does not have any decimal places. It is a whole number, for example, 1,2,3,4 are all integers. 4.3 is not. If you were to try and place the number 4.3 into an integer, the number would​ be truncated to 4.

There are further different types in an integer as well. All of them differ in size which we’ll discuss further down the lesson.

Let’s take a look at them one by one.

Press + to interact
using System;
namespace VariablesExampleOne
{
class Program
{
static void Main(string[] args)
{
sbyte a = -128;
Console.WriteLine("The variable a contains " + a);
byte b = 255;
Console.WriteLine("The variable b contains " + b);
short c = 32767;
Console.WriteLine("The variable c contains " + c);
ushort d = 65535;
Console.WriteLine("The variable d contains " + d);
int e = 2147483647;
Console.WriteLine("The variable e contains " + e);
uint f = 4294967295;
Console.WriteLine("The variable f contains " + f);
long g = 9223372036854775807;
Console.WriteLine("The variable g contains " + g);
ulong h = 18446744073709551615;
Console.WriteLine("The variable h contains " + h);
}
}
}

Float

Floats are floating point numbers with a ...

Access this course and 1400+ top-rated courses and projects.