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 cover the basics of classes, are 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 okay 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, I think I often accidentally go too fast and skip important things that shouldn't be skipped.)
1 - IntroductionWelcome to the world of programming and game making! This introductory tutorial will explain the goals of this tutorial set and briefly describe what programming is, what C# is, and why we want to learn it. |
2 - Installing Visual StudioThis first, real tutorial of the series explains how to install the program you will use to create C# code: Microsoft Visual Studio. (The Community edition is free and still allows you to do commercial development!) |
3 - Hello World: Your First C# ProgramThis 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. |
4 - CommentsThis 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). |
5 - VariablesWith 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. |
6 - Basic MathComputers love math. They eat it for breakfast. In fact, math and reading and writing data are 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. |
7 - User InputNow 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. |
8 - More MathWith 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. |
9 - Decision MakingWe'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! |
10 - SwitchesIn 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. |
11 - LoopingFor our next trick, we'll take a look at loops in C#. Loops allow us to repeat a chunk of code multiple times, giving us a lot of flexibility and power very quickly. |
12 - ArraysSince tutorial #5, we've known how to store data: variables. But what if we want to store large collections of data that all have 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#. |
13 - EnumerationsEnumerations 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. |
14 - MethodsMethods 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 their 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. |
15 - Classes Part 1: Using ThemThis 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. |
16 - Classes Part 2: Making ThemWith learning about the basics of classes in the previous tutorial, this one will show us how to actually make our own classes. |
17 - PropertiesThis 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. |
18 - StructsNow 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. |
19 - InheritanceAs 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. |
20 - Polymorphism, Virtual Methods, and Abstract Base ClassesOur 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. |
21 - InterfacesInterfaces 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. |
22 - Using GenericsGenerics provide a way for us to create container classes (or other classes) that can be 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. |
23 - GenericsIn 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. |
24 - Writing to and Reading from FilesWith 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 that is stored in a file. This tutorial will cover the basics of file input and output. |
25 - Error Handling: ExceptionsWhat 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. |
26 - DelegatesDelegates 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. |
27 - EventsEvents, 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. |
28 - ThreadingThreading 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. |
29 - Operator OverloadingWe'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! |
30 - IndexersLike with operator overloading, indexers allow you to make a custom way for your class to use the indexing operator ([ and ]). |
31 - User-Defined ConversionsUser-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. |
32 - Extension MethodsExtension 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. |
33 - Wrap UpWe'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! |