C# Tutorial
C# (pronounced "C-sharp") is a modern, versatile, object-oriented programming language developed by Microsoft in 2000 that runs on the .NET Framework. Whether you're creating Windows applications, diving into Unity game development, or working on enterprise solutions, C# is one of the top choices for developers worldwide.
- C# originates from the C programming family and shares similarities with other widely-used languages like C++ and Java.
- Mainly used to develop the desktop apps, windows apps, games(with unity engine), mobile apps and web services etc.
- C# is the primary language for developing games using the Unity engine.
- With .NET Core, C# applications can run on Windows, macOS, and Linux.
- The latest version, C# 13 was released in November 2024 alongside .NET 9.
Hello World Program
// C# Hello World Program
using System;
class HelloWorldProgram {
// Main Method
static void Main(string[] args)
{
// "printing Hello World"
Console.WriteLine("Hello, World!");
}
}
Output
Hello, World!
This C# tutorial covers everything from beginners to advanced level. We’ll start with the basics like setting up your environment, C# syntax, and writing "Hello World" program, data types, and loops etc. After that we will start with advanced topics like object-oriented programming, delegates, tuples, indexers, collections, multithreading, and LINQ etc.
.NET Framework Overview
- What is .NET Framework?
- .NET Framework Architecture
- Managed and Unmanaged Code
- CIL or MSIL
- Common Language Runtime(CLR)
Introduction
- What is C#?
- Installing and Setup Visual Studio Code
- Setting Up Enviornment Variables
- Hello World Program
- Excecuting Program on CMD
Basics
- Identifiers
- Variables
- Data Types
- Constants and Literals
- Scope of Variables
- Params
- Type Casting
- Comments
- Operators
Control Structures
- Decision Making: If-Else, Switch-Case
- Switch Statement
- Loops: For, While, Do-While
- Foreach Loop
- Jump Statements: Break, Continue, Goto
Arrays & Strings
- Introduction to Arrays
- Jagged Arrays
- Sorting an Array
- Introduction to String
- Verbatim String Literal – @
- StringBuilder in C#
- String vs StringBuilder
OOPS Concepts
- Class and Objects
- Methods
- Constructors
- Destructors
- Properties
- Access Modifiers
- Abstraction
- Encapsulation
- Inheritance
- Method Overloading
- Method Overriding
- Abstract Classes
- Interface
- Sealed Classes
Delegates
Tuple
- What is Tuple?
- Tuple Class
- Tuple<T1> Class
- Tuple<T1,T2> Class
- Tuple<T1,T2,T3> Class
- Tuple<T1,T2,T3,T4> Class
- Tuple<T1,T2,T3,T4,T5> Class
- Tuple<T1,T2,T3,T4,T5,T6> Class
- Tuple<T1,T2,T3,T4,T5,T6,T7> Class
- Tuple<T1,T2,T3,T4,T5,T6,T7,TRest> Class
ValueTuple
- What is ValueTuple?
- ValueTuple Struct
- ValueTuple <T1> Struct
- ValueTuple <T1,T2> Struct
- ValueTuple <T1,T2,T3> Struct
- ValueTuple <T1,T2,T3,T4> Struct
- ValueTuple <T1,T2,T3,T4,T5> Struct
- ValueTuple <T1,T2,T3,T4,T5,T6> Struct
- ValueTuple <T1,T2,T3,T4,T5,T6,T7> Struct
- ValueTuple <T1,T2,T3,T4,T5,T6,T7,TRest> Struct
Indexers & Properties
Multithreading
- Introduction to Multithreading
- Types of Threads
- Creating Threads
- Main Thread
- Lifecycle and States of a Thread
- Thread Class
- Scheduling a thread for Execution
- Check whether a Thread is Alive or Not
- Joining Threads
- Terminating a Thread
- Thread Priority in Multithreading
Exception Handling
- Exceptions
- System Level Exception vs Application Level Exception
- How to Use Multiple Catch Clause
- Nesting of Try and Catch Blocks
- Using Finally
Collections & Generics
- List
- SortedList with Examples
- HashSet
- SortedSet
- Dictionary with Examples
- SortedDictionary
- Hashtable with Examples
- Stack with Examples
- Queue with Examples
- LinkedList
- Hashtable vs Dictionary
- SortedList vs SortedDictionary
Collections Namespace
Generic Namespace
- HashSet<T> Class
- LinkedList<T> Class
- List<T> Class
- SortedSet<T> Class
- Dictionary Class
- SortedDictionary Class
System Namespace
- BitConverter Class
- Console Class
- Convert Class
- Decimal Struct
- Byte Struct
- Char Struct
- Int16 Struct
- Int32 Struct
- Int64 Struct
- UInt16 Struct
- UInt32 Struct
- UInt64 Struct
Specialized Namespace
- ListDictionary Class
- StringCollection Class
- OrderedDictionary Class
- HybridDictionary Class
- StringDictionary Class
C# 8.0
Windows Forms
- What is Windows Forms(WF)?
- Button Control
- Label Control
- RadioButton Control
- CheckBox Control
- TextBox Control
- ComboBox Control
- ToolTip Class
- RichTextBox Class
- MaskedBox Class
- NumericUpDown Class
- DateTimePicker Class
- ListBox Class
- GroupBox Class
- FlowLayoutPanel Class

C# Features
- Simple: C# is a user-friendly language that offers a structured approach to problem-solving. it provides a wide range of library functions and data types to work.
- Modern Programming Language: C# programming is a popular and powerful language that is for creating scalable, interoperable, and robust applications.
- Object Oriented: C# is an object-oriented programming language, which makes development and maintenance easier. In contrast, with procedure-oriented programming languages, managing code becomes difficult as project size grows.
- Type Safe: The code is type safe can only access memory locations that it has permission to execute. This feature significantly enhances program security.
- Interoperability: The interoperability process allows C# programs to perform all the tasks that a native C++ application.
- Scalable and Updateable: C# is a programming language that is scalable and can be updated automatically. To update our application, we remove the old files and replace them with new ones.
- Component Oriented: It is widely used as a software development methodology to create applications that are more strong and can easily scale.
- Structured Programming Language: C# is a structured programming language that allows us to divide programs into parts using functions, making it easy to understand and modify.
- Fast Speed: The compilation and execution time of C# language is fast.
FAQs
1. What is C# programming language used for?
C# is a versatile programming language primarily used for developing Windows applications, web services, and games within the .NET framework.
2. What is the advantage of ‘using’ statement in C#?
The ‘using’ statement provides resources for processing before automatically disposing of it when execution is completed.
3. What is serialization?
To transport an object through a network, we need to convert it into a stream of bytes. It is called Serialization.
4. What are the four steps involved in the C# code compilation?
4 steps of code compilation in C# include:
- Source code compilation in managed code.
- Newly created code is merged with assembly code.
- The Common Language Runtime (CLR) is loaded.
- Assembly execution is done through CLR.
5. How can I declare and initialize variables in C#?
Variables are named containers that store values of different types. To declare a variable in C#, you need to specify its type and name.