C# from the Inside Out

Nourhan IbrahimNourhan Ibrahim
2 min read

The Anatomy of C# — Full, Simple but Detailed

  1. 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).

  1. 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.

  1. Operators

Arithmetic: + - * / %

Comparison: == != < > <= >=

Logical: && || !

Assignment: = += -=

Null-coalescing: ?? and ??=

Ternary: condition ? value1 : value2

  1. Control Flow

If / else – decisions.

Switch / switch expressions – multiple conditions.

Loops: for, while, do while, foreach.

Jump statements: break, continue, return, goto.

  1. 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 (=>).

  1. 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.

  1. Collections & Data Structures

Arrays ([]).

Lists (List).

Dictionaries (Dictionary<TKey, TValue>).

Queues, Stacks.

HashSet.

ReadOnly collections.

  1. LINQ

Query syntax vs Method syntax.

Filtering: Where().

Projection: Select().

Aggregation: Count(), Sum(), Average().

Ordering: OrderBy(), OrderByDescending().

Joining collections.

  1. Exception Handling

try / catch / finally.

Throwing exceptions (throw).

Custom exception classes.

using statement for resource cleanup.

  1. Events & Delegates

Delegates → references to methods.

Events → publish/subscribe pattern.

Action, Func, Predicate delegates.

Lambda expressions.

  1. 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[]).

  1. Memory & Garbage Collection

Stack vs Heap.

Garbage Collector (automatic cleanup).

IDisposable & using.

  1. Compilation & Execution

Source code → compiled to IL (Intermediate Language).

IL → executed by CLR (Common Language Runtime).

Just-In-Time (JIT) compilation.

  1. Best Practices

Consistent naming conventions (PascalCase, camelCase).

Keep methods small and focused.

Comment only when necessary.

Use var wisely.

Handle exceptions gracefully.

0
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