C#: The Basics

Roadmap: All Tutorials » C# Tutorials » The Basics

Previous: Getting Started Tutorials Homepage
Next: Object-Oriented Tutorials Homepage

These tutorials cover the fundamentals of programming in C#. These tutorials will cover all of the things you absolutely need to know to start working in C#. We'll discuss what variables are and how to use them, as well as arithmetic operations like addition, subtraction, division, and multiplication, as well as how to get your program to make decisions and loop, and conclude with how to separate part of your code into reusable chunks called methods.


basics100.png

1 - 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.
1 - Variables


basics100.png

2 - 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.
2 - Basic Math


basics100.png

3 - 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.
3 - User Input


basics100.png

4 - 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.
4 - More Math


basics100.png

5 - 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!
5 - Decision Making


basics100.png

6 - Switch Statements

Like the basic if-statement we learned about in the previous tutorial, switch statements are a powerful way to make the program do different things in different situations. (In fact, everything a switch statement can do can be done with if statements.) Switch statements, in the right situation, can be very clean and easy to use and understand, so it is worth taking a look at them at this point.
6 - Switch Statements


basics100.png

7 - 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.
7 - Looping


basics100.png

8 - Arrays

Since the first tutorial in this set, 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#.
8 - Arrays


basics100.png

9 - 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.
9 - Enumerations


basics100.png

10 - Methods

Methods are one of the most imporant 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.
10 - Methods