C# (pronounced C-Sharp) is a modern, object-oriented programming language developed by Microsoft. It is widely used for building web applications, desktop applications, cloud services, games, and enterprise software.
- C# runs on .NET, enabling applications to run across Windows, macOS, and Linux.
- Its syntax is similar to other C-based languages such as Java and C++.
Hello World Program
using System;
class HelloWorldProgram
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}
Output
Hello, World!
Why Learn C#?
- Object-oriented and strongly typed programming language.
- Used for web, desktop, cloud, and enterprise application development.
- Widely used with ASP.NET Core for backend and web development.
- Popular for game development with Unity.
- Supported by the modern cross-platform .NET ecosystem.
Basics
Before learning C# programming concepts, install and set up the .NET SDK, install and set up Visual Studio Code for C#, and set up the required environment variables to create and run C# programs.
- Introduction
- Input and Output
- Identifiers
- Keywords
- Variables
- Data Types
- Constants and Literals
- Type Casting
- Comments
- Operators
- Decision Making
- Loops and Jump Statements
Methods
C# methods are reusable blocks of code that perform specific tasks. They help organize programs, reduce code duplication, and improve readability.
- Methods in C#
- Method Parameters
- Return Types
- Method Overloading
- Optional and Function Parameters
- ref, out, and in Parameters
- Recursion
Arrays
C# arrays store multiple values of the same type in a single variable. Elements are accessed using indexes, making arrays useful for organizing fixed-size collections of data.
Strings
C# strings represent sequences of characters and are widely used for text processing. The language provides several built-in features for creating, formatting, comparing, and manipulating strings.
- Introduction to String
- String Formatting
- String Interpolation
- Verbatim String
- StringBuilder
- String Class
- String vs StringBuilder
Object-Oriented Programming (OOP)
C# follows the Object-Oriented Programming paradigm, which organizes programs using classes and objects. OOP concepts help developers create modular, reusable, and maintainable applications.
- Classes and Objects
- Methods
- Constructors
- Destructors
- Properties
- Access Modifiers
thisKeyword- Static Members
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
- Interfaces and Abstract Classes
Collections
C# collections are used to store and manage groups of objects dynamically. Generic collections provide type safety and are generally preferred for modern C# development.
- List
- LinkedList
- HashSet
- SortedSet
- Dictionary
- SortedDictionary
- Stack
- Queue
- ArrayList
- Hashtable
- SortedList
- BitArray
Generics
Generics allow developers to create reusable classes and methods that work with different data types while maintaining compile-time type safety.
- Introduction to Generics
- Generic Classes
- Generic Methods
- Generic Interfaces
- Generic Constraints
- Generic Collections
Exception Handling
C# Exception Handling provides a structured mechanism for handling runtime errors. It allows programs to respond to exceptional situations without terminating unexpectedly.
- Exception Handling
- Try-Catch Block
- Finally Block
- Throw Keyword
- Multiple Catch Clauses
- Custom Exceptions
- Exception propagation
Delegates and Events
Delegates are type-safe references to methods and form an important foundation for callbacks, events, and functional-style programming in C#.
- Delegates
- Anonymous Methods
- Events
- Event Handlers
- Action Delegate
- Func Delegate
- Predicate Delegate
Lambda Expressions
Lambda expressions provide a concise way to define anonymous functions. They are commonly used with delegates, collections, asynchronous APIs, and LINQ.
- Lambda Expressions
- Lambda with Delegates
- Lambda with LINQ
LINQ
LINQ (Language Integrated Query) allows developers to query and transform data directly within C#. It can work with collections, objects, databases, XML, and other data sources.
- Introduction to LINQ
- Query Syntax
- Method Syntax
- LINQ Operators and Methods
- Filtering
- Sorting
- Projection
- Grouping
- Aggregation
File Handling
C# File Handling enables applications to create, read, write, and manage files and directories. File operations are primarily provided through classes in the System.IO namespace.
- File Handling
- File Class
- FileInfo Class
- Directory and DirectoryInfo
- FileStream
- StreamReader and StreamWriter
- BinaryReader
- BinaryWriter
Multithreading and Asynchronous Programming
C# supports concurrent and asynchronous programming using threads, tasks, and async/await. Modern C# applications commonly use higher-level abstractions such as Task and asynchronous APIs.
- Introduction to Multithreading
- Types of Threads
- Creating Threads
- Main Thread
- Thread Lifecycle
- Thread Class
- Thread Synchronization
- Thread Safety and Race Conditions
- Locks
- Task Parallel Library (TPL)
- Tasks
- Async and Await
.NET and CLR
.NET is the development platform on which modern C# applications run. Understanding its runtime and execution model helps developers understand how C# code is compiled, executed, and managed.
- Introduction to .NET
- .NET Framework
- .NET vs .NET Framework
- Common Language Runtime (CLR)
- Intermediate Language (IL)
- JIT Compilation
- Common Type System (CTS)
- Common Language Specification (CLS)
- Managed and Unmanaged Code
- Garbage Collection
- Assemblies
Advanced C#
Advanced C# covers language features used to create flexible, expressive, and maintainable applications.
- Extension Methods
- Pattern Matching
- Attributes
- Nullable Types
- Nullable Reference Types
- Tuples
- Records
- Indexers
- Iterators
- Reflection
Database Connectivity
C# applications can communicate with relational databases using .NET data-access technologies. ADO.NET provides classes for establishing connections, executing commands, and processing database results.
- Introduction to ADO.NET
- Database Connection
- Connection Class
- Command
- DataReader
- DataAdapter
- DataSet
- Parameterized Queries
- Transactions
- CRUD Operations
Quiz and Coding Practice
Practice C# concepts through topic-wise quizzes and coding problems to improve programming knowledge and problem-solving skills.
- C# Topic-wise Quiz
- C# Coding Practice Problems
Interview Questions
This section helps learners revise important C#, .NET, OOP, collections, LINQ, multithreading, and application-development concepts for technical interviews.
- C# Interview Questions and Answers
- .NET Interview Questions
- ASP.NET Interview Questions