C# Overview

An Introduction to Microsoft's Modern, Object-Oriented Programming Language

Welcome to C#

C# (pronounced "C sharp") is a modern, object-oriented, and type-safe programming language developed by Microsoft within the .NET initiative. It combines the productivity of a rapid application development language with the power and flexibility of a compiled language. C# is designed for building a wide variety of applications on the .NET platform, from desktop and web applications to mobile apps, games, and enterprise-level services.

This document provides a foundational understanding of C#, its key features, and how it is used to develop powerful software solutions.

Key Features of C#

Getting Started with C#

To start writing C# code, you'll need the .NET SDK. You can download it from the official .NET download page.

Here's a simple "Hello, World!" program to get you started:

Program.cs
using System;

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

You can compile and run this code using the .NET CLI:

dotnet new console -o MyHelloWorldApp
cd MyHelloWorldApp
dotnet run

Core Concepts

Variables and Data Types

C# is statically typed, meaning you must declare the type of a variable. Common data types include:

Variables.cs
int count = 10;
double price = 99.99;
bool isActive = true;
string message = "Welcome!";

Control Flow

C# provides standard control flow statements:

Classes and Objects

As an object-oriented language, C# uses classes as blueprints for creating objects. Objects encapsulate data (fields or properties) and behavior (methods).

Classes.cs
public class Dog
{
    public string Name { get; set; }
    public string Breed { get; set; }

    public void Bark()
    {
        Console.WriteLine($"{Name} says Woof!");
    }
}

// Usage:
Dog myDog = new Dog { Name = "Buddy", Breed = "Golden Retriever" };
myDog.Bark();

Methods

Methods are blocks of code that perform a specific task. They can accept parameters and return values.

Namespaces

Namespaces are used to organize code and prevent naming conflicts. The using directive allows you to access types within a namespace.

The .NET Ecosystem

C# is the primary language for the .NET platform, which includes:

The .NET ecosystem is constantly evolving, with frequent updates and new features being released.

Further Learning

This overview provides a glimpse into the world of C#. To dive deeper, explore these resources: