C# Programming Language

A modern, powerful, and versatile language by Microsoft

What is C#?

C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft as part of the .NET platform. It is designed to be simple, powerful, and type-safe, making it ideal for building reliable and scalable applications.

Key Features

C# Code Examples

Below are several simple examples demonstrating common C# concepts.

1. Hello World

using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, World from C#!");
    }
}

2. Variables and Data Types

using System;

class Program
{
    static void Main()
    {
        int age = 20;
        double price = 19.99;
        string name = "Alex";
        bool isStudent = true;

        Console.WriteLine(name);
        Console.WriteLine(age);
        Console.WriteLine(price);
        Console.WriteLine(isStudent);
    }
}

3. If-Else Statement

using System;

class Program
{
    static void Main()
    {
        int number = 10;

        if (number > 0)
        {
            Console.WriteLine("Positive number");
        }
        else
        {
            Console.WriteLine("Negative number");
        }
    }
}

4. Loop Example (for loop)

using System;

class Program
{
    static void Main()
    {
        for (int i = 1; i <= 5; i++)
        {
            Console.WriteLine(i);
        }
    }
}

5. Method Example

using System;

class Program
{
    static void Main()
    {
        Greet("C# Learner");
    }

    static void Greet(string name)
    {
        Console.WriteLine("Hello, " + name + "!");
    }
}

6. Simple Class and Object

using System;

class Person
{
    public string Name;
    public int Age;

    public void Introduce()
    {
        Console.WriteLine($"My name is {Name} and I am {Age} years old.");
    }
}

class Program
{
    static void Main()
    {
        Person p = new Person();
        p.Name = "Sam";
        p.Age = 25;
        p.Introduce();
    }
}

What is C# Used For?