A C# Crash Course

Before You Start…

I want to start off by saying thanks for coming here and checking out these tutorials. I think they'll make a huge difference to you as you learn C#!

Let me also say that I know that this is a lot of tutorials. But you don't have to do them all. I'd definitely recommend looking, even just briefly, at all of them so you know what is here, but if you are in a rush, or you're wanting to get started making your game or something, don't feel like you need to go through each of them in great detail.

If you're short on time, I'd say tutorials 1-17, which covers up through the basics of classes, is going to be your best bet. These earlier tutorials tend to be shorter and not as detailed, since they're the basics.

Beyond that, you're probably OK to do other stuff, and come back to these tutorials as needed, or as you have extra time.

If you've got a little more time beyond that, don't skip tutorial #23, about using generics or tutorial #25 about error handling.

Also, if you are extremely rushed, or you are coming from a strong programming background (especially if you know C++ or Java already) you should be able to get away with simply reading the Crash Course sections at the start of every tutorial, and then reading the details if something doesn't make sense.

By the way, I've only just recently completed this set of tutorials, and if you've got suggestions, you're finding something confusing, or you see a typo or a broken link, I'd love to hear about it so I can make these tutorials better for people just learning C#. (I'll admit, having been a programmer for a long time, now, I think I often accidentally go too fast and skip important things that shouldn't be skipped.)

basics100.png

1 - Introduction

Welcome to the world of programming and game making! This introductory tutorial will explain the goals of this set of tutorials, and briefly describes what programming is, what C# is, and why we want to learn it.
Introduction


basics100.png

2 - Installing Visual C# Express

This first, real tutorial of the series explains how to install the program you will use to create C# code: Microsoft Visual C# Express. (It's free; spend your money on a large soda pop instead!)
Installing Visual C# Express


basics100.png

3 - Hello World: Your First C# Program

This tutorial covers your first steps into programming: making a simple C# program that simply prints out "Hello World!". (This is the traditional first program whenever you learn a new programming language.) We then take a quick look at some of the things that appear in every C# program, including a really simple program like this.
Hello World: Your First C# Program


basics100.png

4 - Comments

This tutorial covers how to make comments in a C# application. Comments are a critical part of explaining to other programmers what your code does (and also for reminding yourself of what your code does, when you come back to it later).
Comments


basics100.png

5 - Variables

With some of the basics behind us, we're ready for our first real topic about programming: variables. Variables are a little different from math variables. In programming, a variable is like a bucket to store information, like a player's score, the player's name, the cost of an item, etc. This tutorial discusses the types of variables that a C# program can have, as well as how to create variables, and how to put information in them.
Variables


basics100.png

6 - Basic Math

Computers love math. They eat it for breakfast. In fact, math and reading and writing data is basically all computers can do. But they do it very very fast! This tutorial will show you how to do basic mathematical operations like addition, subtraction, multiplication, and division, along with a few other important concepts to get started doing real work in our programs.
Basic Math


basics100.png

7 - User Input

Now that we've got the fundamentals of math behind us, let's learn one last piece of information that we'll need to really get going making useful programs: getting input from the user! Doing this is very easy. And in the process, we'll create a simple program to tie together everything we've done so far.
User Input


basics100.png

8 - More Math

With the ability to make simple programs behind us, we're going to go ahead and learn some of the more detailed math stuff in C#. This tutorial covers a random collection of things including (don't worry if you haven't heard of any of these, yet) integer division, typecasting, division by zero, infinity, NaN, overflow, underflow, and the increment and decrement operators (++ and —). There's a lot here, and it is not a problem if you read some sections and skip others, and it also isn't a problem if you don't understand it all in a first look. In fact, you won't. Don't worry, you can always come back and revisit this tutorial whenever you want.
More Math


basics100.png

9 - Decision Making

We're really cruising along now, and we're ready to learn a very cool and very important feature of C#, and every "real" programming language: decision making. In C#, this is done with if-statements—special constructs that allow us to run certain lines of code if and only if certain conditions are met. This tutorial will cover everything you need to know to write code that can make decisions for you!
Decision Making


basics100.png

10 - Switch Statements

In this tutorial, we'll cover something that is kind of similar to the if-statements we dealt with in the previous tutorial. This is called a switch statement. A switch statement works like a railroad switch, where the flow of execution can take one of a large number of paths, based on certain conditions. Everything that can be accomplished with switch statements could theoretically be done with if-statements, so they aren't necessary, but they are commonly used, so it is worth discussing.
Switch Statements


basics100.png

11 - Looping

For our next trick, we'll take a look at loops in C#. Loops allow us to repeat a chunk of code multiple times, which gives us a whole lot of flexibility and power very quickly. For people coming from a C++ or Java background, there's not a whole lot to see here—everything works the same way as you'd expect it to. For those of you who are new to programming, this is one of the most important tutorials you see in this set.
Looping


basics100.png

12 - Arrays

Since tutorial #5, we've known how to store data: variables. But what if we want to store large collections of data that all has the same type? For example, what if you have a list of 20 high scores? While you could use simple variables to store each of the 20 high scores, we can store them all together in a single array, or collection. This tutorial will show you how to create and use arrays in C#.
Arrays


basics100.png

13 - Enumerations

Enumerations are a cool feature of C# that allows you to create your own type of variable. In many cases, you have something you want to keep track of, like the day of the week (Sunday, Monday, Tuesday, etc.) that has a certain, small, specific set of choices. Enumerations let you list the possible options, and then use that set of choices throughout your program, just like any other variable type.
Enumerations


basics100.png

14 - Methods

Methods are one of the most important and useful features of C#, and really any programming language. Chunks of code that accomplish a particular task can be pulled off into its own little block (called a method in C#, or a function or procedure in other languages) and reused as needed. This tutorial will discuss everything you need to know about creating and using methods.
Methods


basics100.png

15 - Classes Part 1: Using Them

This tutorial is the first of several that discuss object oriented programming, starting from scratch. This tutorial covers objects and classes, and how to use them, using the Random class for generating random numbers as an example.
Classes Part 1: Using Them


basics100.png

16 - Classes Part 2: Making Them

With learning about the basics of classes in the previous tutorial, this one will show us how to actually make our own classes.
Classes Part 2: Making Them


basics100.png

17 - Properties

This tutorial covers properties, which are a very cool and convenient feature of C# that makes it easy to get and set the values of instance variables. Properties are one of the big features that sets it apart from other languages, like C++ and Java, which do not (yet) provide them.
Properties


basics100.png

18 - Structs

Now that we know about making classes, we'll take a quick look at a feature that appears similar to classes, at a first glance, but behind the scenes is actually quite different: the struct.
Structs


basics100.png

19 - Inheritance

As we continue to learn about object oriented programming, we'll look into a powerful technique for reusing code and expanding on an existing class, using a feature called inheritance. This tutorial will also introduce the protected access modifier.
Inheritance


basics100.png

20 - Polymorphism, Virtual Methods, and Abstract Base Classes

Our adventure in object oriented programming continues, as we discuss polymorphism, a way to allow derived classes to implement a method in different ways, creating virtual methods and overriding them, and creating abstract base classes and abstract methods.
Polymorphism, Virtual Methods, and Abstract Base Classes


basics100.png

21 - Interfaces

Interfaces are similar to the abstract base classes that we discussed in the previous tutorial. Here we'll look at interfaces, which provide simply a list of methods and properties that a class that uses it must implement, and explains the concept of multiple inheritance, why C# doesn't support it, and how to use interfaces to get a similar result. This tutorial will conclude our discussion on object oriented programming.
Interfaces


basics100.png

22 - Writing to and Reading from Files

With an understanding of object oriented programming behind us, this tutorial begins a discussion on some of the random but important other topics in C#. One task that nearly every program requires is the ability to write to a file or read information back in that is stored in a file. This tutorial will cover the basics of file input and output.
Writing to and Reading from Files


basics100.png

23 - Using Generics

Generics provide a way for us to create container classes (or other classes) that canbe used for any different type. This tutorial is one of the more important ones, so don't skip it! We'll take a look at the motivation behind generics, and then we'll look at the very useful List and Dictionary classes. The next tutorial will cover how to make your own classes use generics.
Using Generics


basics100.png

24 - Generics

In the previous tutorial, we looked at how to use classes that use generics. In this tutorial, we'll go into the simple details of how to actually create a class that uses generics.
Generics


basics100.png

25 - Error Handling: Exceptions

What do you do when things go wrong? That's what this tutorial is all about. When things go wrong, you usually end up with what is called an "exception", which is an object that gives you information about what when wrong, and by handling it, we can prevent the program from crashing. This tutorial will cover how to handle exceptions, as well as how to make and "throw" (trigger) your own exceptions.
Error Handling: Exceptions


basics100.png

26 - Delegates

Delegates are a way to treat methods as though they are objects, allowing us to pass them around as parameters to methods or return methods from other methods. They also form the foundation for events, which we'll talk about in the next tutorial.
Delegates


basics100.png

27 - Events

Events, which are built on delegates, are an easy and powerful way for one piece of code to tell another piece of code that something specific has happened. Events are a key part of most GUI driven programs, but even console programs can put them to good use.
Events


basics100.png

28 - Threading

Threading is a programming technique that allows us to run code on multiple processors at the exact same time, making it so your program can run faster, so you can run a task in the background, while another thread keeps a progress bar up-to-date.
Threading


basics100.png

29 - Operator Overloading

We've done a lot with math operations, but this tutorial will show you how you can make it so you can do math with your own classes, using something called "operator overloading". When you're done with this tutorial, you'll know exactly how to use say the '+' operator with your own class!
Operator Overloading


basics100.png

30 - Indexers

Like with operator overloading, indexers allow you to make a custom way for your class to use the indexing operator ('[' and ']').
Indexers


basics100.png

31 - User-Defined Conversions

User-defined conversions are a nice way for us to be able to indicate how our classes can be turned into other types or classes. If it makes sense to be able to convert your class to a similar but different type, this will make it easy to do so. For instance, if you have a MagicNumber class, you can make it so you can turn numbers directly into a MagicNumber, and vice-a-versa.
User-Defined Conversions


basics100.png

32 - Extension Methods

Extension methods are a nifty way to "add" methods to classes that you don't have control over. Technically, we're using a static method that doesn't belong to any class, but with extension methods, C# will magically make it look like the method belongs to the class, which can make your code much more readable.
Extension Methods


basics100.png

33 - Wrap Up

We've covered a ton of C# programming. In fact, more than we really needed to for a "crash course". We've gone into a lot of details that should give you all of the core knowledge you need to go anywhere you want with C#. This "tutorial" will look back on everything we've done, and point out where to go next, now that we're at the end of the C# tutorials!
Wrap Up