C# Documentation

On this page:

Introduction to C#

C# (pronounced "C sharp") is a modern, object-oriented, and type-safe programming language developed by Microsoft. It is designed for building a wide range of applications on the .NET platform, from web applications and services to desktop software, mobile apps, and games.

C# is a versatile language that combines the productivity of a high-level language with the power and performance of a low-level language. It has a rich set of features that make it suitable for developing robust and scalable software.

Key Features of C#

Getting Started with C#

To start writing C# code, you'll need a development environment. The most popular choice is Visual Studio or Visual Studio Code with the C# extension.

  1. Install .NET SDK: Download and install the latest .NET SDK from the official .NET website.
  2. Create a Project: Use the .NET CLI to create a new project:
    dotnet new console -o MyCSharpApp
    cd MyCSharpApp
  3. Write Code: Open the Program.cs file and start coding.
  4. Run: Compile and run your application:
    dotnet run

For a more in-depth guide, check out the Getting Started guide.

Code Examples

"Hello, World!" Program

A simple example demonstrating the basic structure of a C# console application.

using System;

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

Basic Class Definition

Illustrates how to define a simple class and create an object from it.

using System;

public class Person
{
    public string Name { get; set; }
    public int Age { get; set; }

    public Person(string name, int age)
    {
        Name = name;
        Age = age;
    }

    public void Greet()
    {
        Console.WriteLine($"Hello, my name is {Name} and I am {Age} years old.");
    }
}

class Example
{
    static void Main(string[] args)
    {
        Person person1 = new Person("Alice", 30);
        person1.Greet();
    }
}