Utilizor
Contact Us

C# Intro

Introduction to C# (C-Sharp) programming language.

What is C#?

C# (pronounced "C-Sharp") is an object-oriented programming language developed by Microsoft that runs on the .NET Framework.

C# has roots from the C family, and the language is close to other popular languages like C++ and Java.

The first version was released in year 2002. The latest version, C# 12, was released in November 2023.

C# is used for:

  • Mobile applications
  • Desktop applications
  • Web applications
  • Web services
  • Web sites
  • Games (Unity)
  • VR
  • Database applications
  • And much, much more!

Why Use C#?

  • It is one of the most popular programming languages in the world
  • It is easy to learn and simple to use
  • It has a huge community support
  • C# is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs
  • As C# is close to C, C++ and Java, it makes it easy for programmers to switch to C# or vice versa

Examples

Hello World

A simple C# program that prints 'Hello World!' to the console.

using System;

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

Simple Calculation

Adds two numbers and prints the result.

using System;

namespace Calculator
{
  class Program
  {
    static void Main(string[] args)
    {
      int x = 5;
      int y = 6;
      Console.WriteLine(x + y); 
    }
  }
}

Variables Example

Declaring and printing a string variable.

using System;

namespace Variables
{
  class Program
  {
    static void Main(string[] args)
    {
      string name = "John";
      Console.WriteLine(name);
    }
  }
}

Loop Example

A simple loop that prints numbers from 0 to 4.

using System;

namespace Loop
{
  class Program
  {
    static void Main(string[] args)
    {
      for(int i = 0; i < 5; i++)
      {
         Console.WriteLine(i);
      }
    }
  }
}

Condition Example

Checks if one number is greater than another.

using System;

namespace Condition
{
  class Program
  {
    static void Main(string[] args)
    {
      int x = 20;
      int y = 18;
      if (x > y) 
      {
        Console.WriteLine("x is greater than y");
      }
    }
  }
}