.NET Documentation

C# Language Overview

C# is a modern, object-oriented, and type-safe programming language developed by Microsoft. It runs on the .NET platform and is designed for building a wide range of applications, from desktop and web applications to mobile apps and cloud services. C# combines the power of C++ with the ease of use of Visual Basic.

Key Features of C#

Basic Syntax and Structure

A typical C# program consists of classes, which contain methods. Methods define the executable code. Here's a very simple "Hello, World!" example:


using System;

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

In this example:

Fundamental Data Types

C# provides a rich set of built-in data types:

Example declaration:


int age = 30;
string name = "Alice";
double price = 19.99;
bool isActive = true;
            

Variables and Constants

Variables are used to store data. Constants, declared using the const keyword, store values that cannot be changed after they are initialized.


// Variable
int counter = 10;
counter = 20; // Valid

// Constant
const double PI = 3.14159;
// PI = 3.0; // This would cause a compile-time error
            

Control Flow Statements

C# offers various control flow statements to manage the execution path of your program:

Object-Oriented Programming (OOP) Concepts

C# fully embraces OOP principles:

Further Reading

This overview provides a glimpse into the C# language. For a deeper understanding, explore the following topics: