πŸŽ“ A1Learner
πŸ”

C# Introduction

C# is a programming language for building programs that run on many kinds of computer. Programs in C# can make games, websites, and desktop apps.

A first program

This program prints one line. The Main method holds the print line.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("My first C# program");
    }
}

Two lines in order

Programs run from top to bottom. The first print line runs before the second one.

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("First line");
        Console.WriteLine("Second line");
    }
}

Example

using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("C# is a programming language");
        Console.WriteLine("C# runs on many computers");
        Console.WriteLine("C# code is plain text");
    }
}

Key points

  • C# code is plain text in a file.
  • A compiler turns C# code into a form a computer can run.
  • Every program in this course lives in a class named Program.
  • The Main method is where running starts.
  • Console.WriteLine prints one line of text.

In this example, the program prints three lines in order. The first line names the language. The second line says where it runs. The third line says what the code is.

Note

C# is pronounced C sharp.

Try it Yourself

Edit the code, then press Run.

Running is simulated Β· Programiz C# Compiler

Exercise

Which line prints text to the screen?