C# from the Inside Out


The Anatomy of C# — Full, Simple but Detailed
Structure of a C# Program
using directives → import namespaces (like adding tools to your toolbox).
Namespace → logical grouping for classes.
Class → blueprint for objects.
Main method → entry point of the program.
Assembly → the compiled output (.exe or .dll).
Data Types & Variables
Value types (int, bool, double, struct, enum) → store data directly in memory.
Reference types (string, object, arrays, classes) → store a reference (pointer) to the data.
Nullable types (int?) → allow null values.
Constants & Readonly → values that don’t change.
Operators
Arithmetic: + - * / %
Comparison: == != < > <= >=
Logical: && || !
Assignment: = += -=
Null-coalescing: ?? and ??=
Ternary: condition ? value1 : value2
Control Flow
If / else – decisions.
Switch / switch expressions – multiple conditions.
Loops: for, while, do while, foreach.
Jump statements: break, continue, return, goto.
Methods & Parameters
Method declaration: return type + name + parameters.
Parameter types:
By value (default)
ref (pass by reference)
out (output only)
params (variable arguments)
Overloading → same name, different parameters.
Optional parameters.
Expression-bodied methods (=>).
Object-Oriented Programming
Classes & Objects.
Fields & Properties (get; set;).
Constructors (default, parameterized, static).
Inheritance (: baseClass).
Interfaces (interface).
Abstract classes (abstract).
Polymorphism (virtual, override, new).
Encapsulation (access modifiers: public, private, protected, internal).
Sealed → prevent inheritance.
Static members.
Collections & Data Structures
Arrays ([]).
Lists (List).
Dictionaries (Dictionary<TKey, TValue>).
Queues, Stacks.
HashSet.
ReadOnly collections.
LINQ
Query syntax vs Method syntax.
Filtering: Where().
Projection: Select().
Aggregation: Count(), Sum(), Average().
Ordering: OrderBy(), OrderByDescending().
Joining collections.
Exception Handling
try / catch / finally.
Throwing exceptions (throw).
Custom exception classes.
using statement for resource cleanup.
Events & Delegates
Delegates → references to methods.
Events → publish/subscribe pattern.
Action, Func, Predicate delegates.
Lambda expressions.
Advanced Language Features
Generics (List, Dictionary<TKey, TValue>).
Attributes ([Obsolete], custom attributes).
Async / Await (asynchronous programming).
Tasks & parallel programming.
Records (immutable data types).
Pattern matching (is, switch).
Tuples ((int, string)).
Extension methods.
Indexers (this[]).
Memory & Garbage Collection
Stack vs Heap.
Garbage Collector (automatic cleanup).
IDisposable & using.
Compilation & Execution
Source code → compiled to IL (Intermediate Language).
IL → executed by CLR (Common Language Runtime).
Just-In-Time (JIT) compilation.
Best Practices
Consistent naming conventions (PascalCase, camelCase).
Keep methods small and focused.
Comment only when necessary.
Use var wisely.
Handle exceptions gracefully.
Subscribe to my newsletter
Read articles from Nourhan Ibrahim directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nourhan Ibrahim
Nourhan Ibrahim
Full Stack Engineer | Product Designer Electronics Engineering Student Taekwondo Player🥋 https://linktr.ee/nouribram