Ebooks

C# language

In this part of the C# tutorial, we introduce the C# programming language.

Goal

The goal of this tutorial is to get you started with the C# programming language. The tutorial covers the core of the C# language, including variables, arrays, control structures and other core features. This tutorial uses a command line compiler to build applications. It does not cover graphical interface development or visual IDEs.

C#

C# is a modern, high-level, general-purpose, object-oriented programming language. It is the principal language of the .NET framework. It supports functional, procedural, generic, object-oriented, and component-oriented programming disciplines. The design goals of the language were software robustness, durability and programmer productivity. It can be used to create console applications, GUI applications, web applications, both on PCs and embedded systems. C# was created by Microsoft corporation. The name "C sharp" was inspired by musical notation where a sharp indicates that the written note should be made a semitone higher in pitch.

.NET Core

.NET Core provides a fast and modular platform for creating server apps that run on Windows, Linux, and macOS. It is an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub.

$ dotnet --version
2.1.500    

In order to work with .NET Core, we need to dowload and install .NET Core SDK.

Compiling C# programs

After installing .NET Core SDK, we can build our first C# program.

$ dotnet new console -o Simple

With the dotnet new console command, we create a new console application.

Program.cs
using System;

namespace Simple
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This is C#");
        }
    }
}

This is a simple C# program that prints a message to the console.

$ dotnet run
This is C#

We compile and run a simple C# program with dotnet run.

Visual Studio Code

Visual Studio Code is a lightweight, powerful, modern source code editor which is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages and runtimes including C# and .NET Core.

It includes support for debugging, embedded Git control, syntax highlighting, intelligent code completion, snippets, and code refactoring.

Sources

The following sources were used to create this tutorial:

In this part of the C# tutorial, we have introduced the C# language.