Introduction to C#

by mahidhar

Overview of C#
What is C#?
C# (pronounced "C-sharp") is a modern, object-oriented programming language developed by Microsoft as part of its .NET initiative. It was first released in 2000 and has since become one of the most popular programming languages for developing a wide range of applications, including web, desktop, mobile, and cloud-based applications.

History of C#

2000: C# was introduced alongside the .NET Framework.
2002: C# 1.0 was released.
2010: C# 4.0 introduced dynamic binding, named and optional arguments.
2017: C# 7.0 brought pattern matching, tuples, and local functions.
2020: C# 9.0 introduced records, init-only properties, and top-level statements.
Ongoing: C# continues to evolve with new features and enhancements.
Uses of C#

Web Applications: Using ASP.NET Core for high-performance web applications and APIs.
Desktop Applications: Using Windows Forms and WPF.
Mobile Applications: Using Xamarin for cross-platform mobile applications.
Game Development: Using Unity for creating 2D and 3D games.
Cloud-Based Applications: Leveraging Azure services for scalable cloud solutions.
Setting Up the Environment
Installing Visual Studio

Download: Visit Visual Studio Downloads and download the latest version.
Installation: Run the installer, choose the workloads relevant to C# development, such as .NET desktop development and ASP.NET and web development.
First Project: After installation, open Visual Studio, create a new project, choose "Console App (.NET Core)" or "ASP.NET Core Web Application", and follow the prompts to create your first project.
Installing Visual Studio Code and .NET SDK

Download VS Code: Visit Visual Studio Code and download it.
Install .NET SDK: Visit .NET Downloads and download the SDK for your operating system.
Setup First Project:
Open a terminal and run dotnet new console -o HelloWorldApp.
Navigate to the project folder cd HelloWorldApp.
Run the application using dotnet run.
Basics of C#
Syntax and Structure
Basic Syntax and Structure of a C# Program
A simple C# program consists of a namespace, class, and the Main method, which is the entry point of the application.

Example: Simple HelloWorld Program

code
using System;

namespace NationalParks
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the National Parks Information System!");
        }
    }
}

Explanation:

using System;: Imports the System namespace.
namespace NationalParks: Defines a namespace to organize code.
class Program: Defines a class named Program.
static void Main(string[] args): Entry point of the program.
Console.WriteLine: Outputs text to the console.