C# Sharp



 

C# Overview with Example

C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft. It is widely used for building Windows applications, web apps, and games (with Unity). C# runs on the .NET framework, which provides an extensive library and runtime environment for executing programs.

Key Features of C#:

  • Object-Oriented: C# supports the principles of object-oriented programming (OOP), including inheritance, polymorphism, encapsulation, and abstraction.
  • Strongly Typed: It enforces strict type-checking during compile time.
  • Memory Management: C# has automatic garbage collection to manage memory usage.
  • Cross-Platform: With .NET Core, C# applications can run on Windows, Linux, and macOS.

Example: Basic C# Program

 
using System;

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

        // Variables
        int number = 5;
        string message = "Welcome to C# programming!";
        
        // Conditional statement
        if (number > 0)
        {
            Console.WriteLine(message);
        }

        // Loop
        for (int i = 0; i < number; i++)
        {
            Console.WriteLine($"Loop iteration: {i + 1}");
        }
    }
}

 

Explanation:

  • The Main method is the entry point of a C# console application.
  • It defines variables and demonstrates simple logic with conditional statements and loops.
  • The Console.WriteLine method outputs data to the console.