Utilizor
Contact Us

C# Get Started

How to setup C# environment.

C# IDE

The easiest way to get started with C# is to use an IDE.

An IDE (Integrated Development Environment) is used to edit and compile code.

In our tutorial, we will use Visual Studio Community, which is free to download from Microsoft.

Applications written in C# use the .NET Framework, so it makes sense to use Visual Studio, as the program, the framework, and the language, are all created by Microsoft.

C# Install

Once Visual Studio is installed, you can start creating a new project:

  1. Open Visual Studio
  2. Click on "Create a new project"
  3. Select "Console App (.NET Core)" from the list and click "Next"
  4. Enter a name for your project, and click "Create"

Visual Studio will automatically generate some code for your project:

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");    
    }
  }
}

Examples

First Program

The classic 'Hello World' program.

using System;

namespace HelloWorld
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Hello World!");    
    }
  }
}

Running Code

Simple output to verify setup.

using System;

namespace Test
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("It works!");    
    }
  }
}

Multiple Lines

Printing multiple lines.

using System;

namespace MultiLine
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Line 1"); 
      Console.WriteLine("Line 2"); 
    }
  }
}

Using Namespace

Code inside a custom namespace.

using System;

namespace MyNamespace
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Namespace Example");
    }
  }
}

No Arguments

Main method without string[] args parameter.

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Main without args");
    }
}