C# Programming: Get Started Building Powerful ASP.NET Apps

Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

C# is a general-purpose programming language, very much tied to Microsoft’s .NET Framework. It is pronounced “c-sharp” like the musical note — as in C but better (higher). Much like C++, it is an extension of the C programming language with the major addition being object-oriented capabilities.

What is probably most important about C# is that it is now the primary language for .NET programming. At one time Visual Basic had that honor. But most serious .NET coders tend toward C#.

The Two Big C# Uses

Generally speaking, there are two ways that people use C#: as a standalone programming language like you would use C++, and as a server-side language for ASP.NET. This resource will focus on its use as a standalone language. See our ASP Resources page for its use as a server-side language.

As a general purpose language, C# (along with the .NET Framework) can do anything you could ask for in a programming language. And because it is used on Microsoft products, it allows you to create distributed components that can be used inside other programs. It is also a very popular language for creating Android apps.

C# History

C# is a direct result of the .NET Framework. The framework had been developed with Simple Managed C — the Common Language Runtime (CLR) virtual machine compliant C language.

In 1999, Microsoft decided to build its own language based on C, which it originally called COOL — an acronym for C-like Object Oriented Language. It was very much like C++ and Java, although over time, C# has become more distinct.

Versions

As of July 2015, C# is at version 6. It is quite a different language than it was 13 years earlier when the first version was released. For a basic overview of the versions and details on the newest version, see What’s New for Visual C#.

  • V01 (2002): This was the first version that established the basic syntax of the language. It was introduced with and for the .NET Framework 1.0. It was released with Visual Studio 2002. There was a C# version 1.2, which updated it to the .NET Framework 1.1.

  • V02 (2005): This version added a lot of little things. Of particular note is generic types, which greatly help in creating reusable code. It was released with Visual Studio 2005 and the .NET Framework 2.0. See What’s New in the C# 2.0 Language and Compiler for details.

  • V03 (2007): This version was a major upgrade. In addition to many other features, it introduced extension methods, which allow the coder to add to an already compiled class. It was released with Visual Studio 2008 and the .NET Framework 3.0. See Overview of C# 3.0 for details.

  • V04 (2010): This version introduced dynamic late-binding, making it much easier to use with libraries outside the .NET Framework. It shipped with Visual Studio 2010 and the .NET Framework 4.0. See What’s New in Visual C# 2010 for more details.

  • V05 (2012): This version greatly expanded the ability to create asynchronous methods, thus cutting down on coding bottle necks. It was released with Visiual Studio 2012 and the .NET Framework 4.5. See An Introduction to New Features in C# 5.0 for details.

  • V06 (2002): This version is primarily an updated and improved compiler, but there are, of course, many small additions. It ships with Visual Studio 2015 and the .NET Framework 4.6. For more information, see What’s New in C# 6.

Very Basics of C#

C# and the .NET Framework is a very big subject, as will become clear in the resources below. But before getting to them, let us provide a very brief introduction to the language. If you are familiar with C++ or Java, it will look very familiar.

But even for C coders, it will look somewhat familiar. In fact, it doesn’t even look that different from PHP. So most people with programming experience should find C# fairly easy to get started with.

For this purpose, we are going to use the standard Hello World! application. Unlike most C# programs, this one is console (text) based. First, we will present it and then we will explain it. But remember that this is as basic as it gets:


// This is the HelloWorld program...
using System;
namespace HelloWorld
{
  class Program
  {
    static void Main() 
    {
      Console.WriteLine("Hello World!");
    }
  }
}

The first line of the code is a comment. Any text on any line that follows two slash characters is ignored.

The using tells C# that you will be using the System classes, so that when you later use the Console class, you won’t have to explicitly call it as such with System.Console.

The namespace command is not strictly necessary. It provides a way of limiting the scope of classes. So you could conceivably have another Hello class inside a different namespace.

Once we have our namespace set up, we create our Program class. It could be named anything, but this is the default. And it is descriptive. The class has only a single method: Main(). This is where the program starts — and ends.

Inside our incredibly simple Main() method, we run the WriteLine() method with the argument “Hello World!” This does exactly what you would think: it writes the line of text “Hello World!” to the console. The WriteLine method is part of the Console object, which is how it knows where the line should be written.

Pretty simple? Well, even this example can get more complex. See Example 3 in the Hello World Tutorial for what things look like when you want to process command line parameters. And of course, there is much more. So it is onto the resources!

Resources

If you are serious about programming with C#, you are probably best to get a book on the subject. There are many online resources, but at least at the beginning, you may find a thorough introduction more clear.

It isn’t a question of one or the other. The natural progression is to move from books, to online tutorials and examples, to communities of C# programmers. But you will probably find yourself using all three at the same time.

C# Books

Books are a great way to learn for a number of reasons. The most important is that they guide you through a set path. With online tutorials, it is often easy for them to assume you know something you haven’t covered before. Here is a small list of good books. But there are many more available and new ones being written all the time.

Online Resources

Many generous people have spent a lot of time putting together excellent and free resources to help you to become and improve as a C# programmer. This list is certainly not exhaustive, but it includes the best online resources.

  • Learn C#: this is a set of 9 simple tutorials that will teach you the basics. Created by learnCS.org, what’s special about it is that the tutorials are interactive, so you can change the example code and see how it works.

  • Zet Code C# Tutorial: this is a fairly limited set of tutorials, but they are very thorough on the subjects they cover.

  • C# Tutorial for Absolute Beginners: for those who prefer lectures, this is a set of 25 video episodes that walk you through the process of learning the C# language. It is presented by .NET programmer Bob Tabor and is over 6 hours long in total. You can also find the individual episodes at Channel 9.

  • Tutorials Point C# Tutorial: this provides 28 short tutorials ranging from the very basics up to more advanced subjects like polymorphism and namespaces. This site allows you to run each of the examples (in addition to any changes you wish to make) in a popup window.

  • The Complete C# Tutorial: although the name is a bit of an overstatement, these 49 short lessons do cover the most important aspects of the language — with a good emphasis on classes.

  • Hanspeter Mössenböck C# Tutorials: there are two different tutorials here — one introductory and the other advanced. You need to have a fair knowledge of programming in general to get much out of these.

  • Getting Started with Visual C#: ultimately, this is where all the C# information resides — from Microsoft itself. This can be a bit much for novices, but it is an excellent resource. Of particular interest is its set of tutorials.

Online C# Communities

There are times when you just can’t figure out a programming problem, and you need to talk to other programmers about it. And there are times when you just want to discuss programming issue, project ideas, or whatnot with others who share your interests.

Online communities are a great place for this.

Tools

The Visual Studio platform provides all the basic tools that you need to be a successful C# programmer. But there are various add-ons and extensions that you might find useful under some circumstances.

What’s more, there are tools you might want to use outside of Visual Studio. Or you may wish to work outside of Visual Studio altogether.

  • C# Tools: this is a great collection of programming tools of specific interest to C# coders.

  • Development Tools and Languages: this provides links to all of Microsoft’s development tools including Visual Studio and SDKs.

  • MZ-Tools: this is a commercial Visual Studio add-on that offers specialized designers, code templates, and more.

Summary

C# (along with the .NET Framework and Visual Studio) is an enormous subject. You could spend your whole life using it and never discover all of its secrets.

It is a great foundation for any programming that you need to do for the Microsoft platform or for mobile devices. So dive into one or more of the resources here and get going on your way!

Frank Moraes

About Frank Moraes

Frank has worked in the tech industry since the early 1990s — as a writer, programmer, and manager. He’s an insatiable blogger and “Don Quixote” fanatic. In his spare time, Frank writes experimental plays — usually involving puppets like Grumpy Squirrel in his image.

Comments

Thanks for your comment. It will show here once it has been approved.

Your email address will not be published. Required fields are marked *