C# - Programming Language
This course covers the basics of programming in C#. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!
I'm starting a coding bootcamp
Want to learn web development in a fun and gamefied environment? Head over to simulator.dev and see what I'm working on!

Data Types

Lesson 5
Author : Mike Dane
Last Updated : November, 2017

As we write more and more complex programs in C#, we'll want to work with different types of data (data types). Maybe in one program we'll print out someone's favorite movie, in another we'll keep track of how much money a particular product costs, and maybe in another we'll ask someone if they're an organ donor. In everyday life we deal with all different types of data, so why should it be any different for programs?

Many programming languages, including C# allow you to work with and keep track of only a specific few types of data. Now that might not sound like a lot, but when you think about it, almost all data can be broken down into one of three data types.

  • Text (often called strings or chars) - Names, addresses, the text on this page, etc.
  • Numbers - Monetary amounts, dates, distances, etc.
    • integers - whole numbers and
    • floats (also called doubles) - decimal numbers
  • True/False Values (often called booleans) - If someone is an Amazon Prime member, if someone is in the military, if a tv show has been cancelled, etc. This type of data may be less intuitive to a new programmer, but trust me you'll learn to love true/false logic.

With just these three fundamental types of data, we can keep track of almost anything. In fact these are the three fundamental types of data that make up just about every program you'll encounter as a software developer.

Now because these are three distinct types of information, C# is going to handle them a bit differently. There will be certain things we can do with numbers that we can't do with strings or text (like division, multiplication, etc). There will also be a whole range of things we can do with boolean values (true/false) that we can't do with strings or numbers.

Anytime you're writing a program that's keeping track of different pieces of information, you always want to be aware of what data types you're using. For more specific information about how these data types work, and how to use them in C#, check out the video above where we'll dive into them more specifically!

Video Code

Copystring name = "Mike";    // String's are objects not primitives
char testGrade = 'A';    // single 16-bit Unicode character.

// short, int, long can be pre-pended with 'u' for 'unsigned'
byte age0 = 0;           // 8-bit unsigned integer
short age1 = 10;         // 16-bit signed integer.
int age2 = 20;           // 32-bit signed integer
long age3 = 30L;         // 64-bit signed integer

float gpa0 = 2.5F;       // 32-bit floating point
double gpa1 = 3.5;       // 64-bit double-precision floating point
decimal gpa2 = 4.5M;     // 128-bit precise decimal

bool isTall;             // 1 bit -> true/false
isTall = true;

name = "John";

Console.WriteLine("Your name is " + name);
Console.WriteLine($"Your name is {name}");