“The buckets holding electrons…”
// 01. Introduction
This is where you learn how to hold electrons. Programs need something to store data. Variables are to the rescue! A program might need to store bytes, [simple_tooltip content=”A character is a single letter or digit wrapped in single quotes: ‘A’ or ‘3’”]characters[/simple_tooltip], [simple_tooltip content=’A string is a single letter or multiple letters or digits wrapped in double quotes: “Monday” or “1985” ‘]strings[/simple_tooltip], [simple_tooltip content=’1, 2, 3, 4, 5′]whole numbers[/simple_tooltip], [simple_tooltip content=’3.14159, 9.68′]decimals[/simple_tooltip], or entire collections of this stuff. So, lets get down to it!
Almost forgot to mention, when you hear the term “Type”, it means an instance of that class, or an object of that class. What’s a class? What’s this thing called instantiation? Well, when you were born, you were instantiated. You are an instantiation of a set of blueprints (one from your father and mother). They were instantiations of another pair of blueprints. In Software Development land, blueprints are called Classes. When you build something with a blueprint (class), it becomes an object (an instantiated object or Type).
// 02. Data Types
// A. The Byte
Data Type: byte
You won’t be using bytes often, unless you are working with data security, encryption, advanced file management, or converting data between bytes and other types. You might do this when working with data streams later on in your life as a developer. For now, just know that it is there.
// B. The Character
Data Type: char
This guy is much more useful to you now. The character stores, one key, one character, one digit. We could convert the char into a byte and just use bytes all day long, but that was so 1980s (I can say that, because I am an 80s kid.) We use the char for a lot of things, believe it or not. We will eventually use this for parsing text files, comma separated value (CSV) files, testing for user input – ‘Y’ or ‘y’ for yes and ‘N’ or ‘n’ for no; that sort of thing.
// C. The String
Data Type: string
This guys is used way too much! Think of a string like a line with a bunch of hanging characters on it. Oh, wait, that sounds bad, especially if you work at Disney World. Sorry!
// D. The Integer
Data Type: int
The Integer is a whole number. Use this for storing a person’s age, unique ID, just not their Social Security Number…that would be bad!
// E. The Double
Data Type: double
There are a few different ways to store decimal numbers in a computer. Ultimately it comes down to how precise the number needs to be. The Double is the default type for dealing with decimals in C#, so when in doubt, double it out!
// F. The Float
Data Type: float
The float, who uses a float anymore? Honestly, I really don’t know. The two decimal types that I use are the double and the decimal. Use the float if you must, but if precision is what you are after, use the decimal.
// G. The Decimal
Data Type: decimal
The decimal is all about precision. If you are into scientific calculations, financial calculations, doing crazy math with Pi, then the decimal is your friend, mi amigo (that’s my friend…in Spanish).
// H. The Boolean
Data Type bool
Do you get it? I just asked you a question…do you get it? Okay, I am looking for a “Yes” or “No” here. In other words, I am looking for a True or False. Guess what, that is exactly what a bool holds.
// 03. Collection Types
// A. The Array
Arrays are a string of containers that only hold the type you assign it. If you make an array of strings, then you can only put strings into the array. Also, once you make the array a certain size, it can’t grow larger. So, this is best used for things are constant, like the months in a year, days in a month, seconds in a minute, etc.
// B. The ArrayList
The ArrayList is just like an array, just that it will grow in size if you need it too.
// C. The List
The List is just like the ArrayList, just that it stores objects. What that means is that it will hold an integer, string, and decimal if you want it to. I wouldn’t recommend it. You know what they say, “you’ve got to keep them separated!” (cue music now)
// D. The Dictionary
Now we get to make Webster find a new profession! No, not exactly. The dictionary allows us to store meaningful data together, such as “Jan”:”January” or “Mark Filter” : “Funny Guy”. This will come in handy when we talk about saving information to the hard drive or getting information from other websites.