Learn C# (Introduction and Tutorials to C++ Programming)

Learn C# Programming

The Definitive Guide

C# (pronounced as C sharp) is a general purpose, object oriented programming language. C# is one of the most popular language used for developing desktop and web application.

C# is syntactically similar to its competitor Java. Being a C based language, C# is closer to C++ and C as well.

This guide will provide us all the information you need to know about C# programming language before diving into it. We will talk you through its features, application areas and the best practices for writing codes in C#.

What is C# (programming language)?


Before moving any further, let's get familiarized with the language first.

Brief History

Anders Hejlsberg in 1999 led a team to build a new language called Cool (C-like Object Oriented Language). Later the name was changed to C# for trademark reasons.

Reason Behind the name 'C#'

The name C# or C sharp was inspired from a musical note. The symbol # in C# represents four '+' signs and is named similar to C++. '++' in programming indicates an increment by 1.

C++ is an increment in C and similarly C# is an increment in C++.

Different versions of C#

Version Date
C# 1.0 January 2002
C# 1.1 and 1.2 April 2003
C# 2.0 November 2005
C# 3.0 November 2007
C# 4.0 April 2010
C# 5.0 August 2012
C# 6.0 July 2015
C# 7.0 March 2017

Features of C# Programming Language

  1. Simple to write and understand

    C# is syntactically very similar to Java. It also borrows certain concepts from C++. The code written in C# is much simpler and easier to understand.

    For a person with experience in Java and/or C++, C# won't be a difficult language to learn.
  2. Object oriented

    Like Java and C++, C# is an object oriented programming language. It supports the features of object oriented paradigm such as objects, classes, inheritance, polymorphism, etc.

    Object oriented approach is not only easier and simpler but the preferred way of writing programs.
  3. Type safe

    One of the peculiar feature of C# is type safety. A type safe language ensures that each variable of particular type does not hold values of other type. For instance, an integer variable will not hold character values.

    The advantage of type safe language is that possible errors are being checked during compile time rather than in run time.
  4. Modern

    C# is a modern language which is built based on the current trend. C# is a powerful language which allows developers to build robust application quickly and easily.

    It has many advanced features which we will be discussing as we move along with this tutorial series.

5 Reasons why you should learn C#?


When you start learning a new programming language, it is important to know about the prospect of the language. Is the language really helpful? Is it worth learning it? Before diving into a new programming language, these are the things you must know.

Here are some reasons why you should learn C#.

  1. Easy to start

    C# is easy to start with. Being a high level language, the basic constructs of C# is easy to understand. C# is closer to other popular languages like Java and C++. So it is very easy for someone with experience in these programming language to switch to C#.
  2. Widely used for developing Desktop and Web Application

    C# is widely used for developing desktop and web application. According to 2017 survey of StackOverflow, C# is 3rd most popular language used by professional desktop and web application developer. If you are not familiar with stackoverflow, it is the most popular programming Q&A site.

    Beside web and desktop, C# is also popularly used by DevOps engineer and data scientists.
  3. Community

    Community is one of the most important factors to be considered before moving into a new programming language. The larger the community is, the more support you are likely to get.

    C# has a huge community. It has one of the largest community in StackOverflow. So, a C# related question is more likely to be answered in StackOverflow.
  4. Game Development

    Unity is the most popular game engine with a very large community. And C# is often the recommended language to be used along with unity game engine for making games.

    So if you are interested in game development, C# is definitely the language you are looking for.
  5. Future as a C# developer

    C# was developed by Microsoft and is still being maintained by them. C# is the choice of language for making apps in Windows platform.Since C# is backed up by Microsoft, it is going to be in the market for a long time.

    Therefore, the future with C# seems pretty good.

Compile and run C# programming on your OS


The easiest way to get started with C# is using Visual Studio Code (VS Code). VS Code is a lightweight cross platform code editor which runs on Linux, Windows and Mac. It is free and open source which happens to support many programming languages.

So without wasting any time, let's get started.

Run C# on Linux

Download and Install Visual Studio Code

For Debian and Ubuntu based distributions

  1. Download the 64 bit .deb package.
  2. Install the package either using the graphical software center or using the following commands:
    cd Downloads # Assuming the package is in the Downloads folder
    sudo dpkg -i <file>.deb # Replace <file> with the filename
    sudo apt-get install -f # Install dependencies
  3. Then update the package cache and install the package using the following commands:
    sudo apt-get update
    sudo apt-get install code # or code-insiders

For RHEL, Fedora and CentOS based distributions

  1. The following commands will install the key and repository:
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
  2. Then update the package cache and install the package
    For Fedora 22 and above:
    dnf check-update
    sudo dnf install code
    For Fedora 22 and below:
    yum check-update
    sudo yum install code

Install .NET core

For Linux Mint 18 or Ubuntu 16.04

  1. The following command will download and install .NET Core:
    sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
    sudo apt-get update
  2. Install .NET Core SDK using the following command:
    sudo apt-get install dotnet-dev-1.0.4

For other version of linux, visit Install C# for Linux.

Run C# on Mac OS

Download and Install Visual Studio Code

  1. Go to https://code.visualstudio.com/download and download VS Code for Mac.
  2. Install the downloaded file.

Install .NET core

  1. Go to https://www.microsoft.com/net/core#macos and download .NET Core SDK for Mac.
  2. Install .NET Core on your device.

Run C# on Windows (XP, 7, 8 and 10)

Download and Install Visual Studio Code

  1. Go to https://code.visualstudio.com/download and download VS Code for Windows.
  2. Double Click on the downloaded file and perform regular installation.

Install .NET core

  1. Go to https://www.microsoft.com/net/core#windowscmd and download .NET Core SDK for Windows.
  2. Perform a double click installation on the downloaded file.

Install C# extension for Visual Studio Code (For all OS)

  1. Open Visual Studio Code.
  2. Click on extension icon on the left or press Ctrl+Shift+X and type C# in the search bar as shown in image.
    C# extension search by typing c#
  3. Select the first option and install the C# extension.
    C# extension installation
  4. After the extension is installed, we are ready to run C# codes in Visual Studio Code.

Your first C# program


Once you have successfully installed all the requirements for C#, it's time to write your first program.

The first program you will be writing while learning a new programming language is the "Hello World" program. It is one of the simplest program to write in any programming language. The output it will produce is a "Hello World" string.

We will write our C# code using Visual Studio Code which we have installed on our system.

  1. Open terminal or command prompt.
  2. Using the cd command, navigate to the folder where we want to create your project.
  3. Enter the command:
    dotnet new console
  4. This command will initialize a new project and create a Program.cs file in that directory.
  5. Open Visual Studio Code.
  6. Go to File > Open Folder.
  7. Open the folder where you have created your project.
  8. Click on Program.cs (on the left sidebar) to view the file.
  9. The "Hello World" program will be there by default, however you can copy the code below and replace the content of Program.cs.
    using System;
    namespace HelloWorld
        class Hello
            static void Main (string[] args)
                Console.WriteLine("Hello World!");
  10. Go to File > Save (or Press Ctrl + S).
  11. On your terminal or command prompt, type:
    dotnet restore
  12. This command will collect all the dependencies required to run your program.
  13. Type the following command on terminal or command prompt to see the output:
    dotnet run

To know how the "Hello World" program runs, see our C# Hello World program tutorial.

How can you learn C#?


Learn C# from Programiz

Programiz offers a complete series of easy to follow C# tutorials along with suitable examples. These tutorials are targeted for absolute beginners with no prior knowledge of C# programming language.

Subscribe now to get updated about our tutorials.

Official C# Documentation

Since C# was developed by Microsoft, Microsoft has managed to maintain a high quality documentation for C#. These documentation are continuously updated to keep up with the changes in C#.

Although it's a great place to learn C#, it may not be the best place for beginners.

Following a book is always a good way to learn programming. It may take a bit more time but you will learn the best practices for writing codes, grasp the core programming concepts.

Here are some books which we feel is good for you.

Final Words

C# is a fantastic language to learn. It follows object oriented methodologies for writing code. Hence, it is easier to manage large projects in C#. C# may not be the first language to learn, but it is definitely an awesome language for building a career.