10 Core Concepts • 5 Key Differences • Real Code Examples
| # | Abstract Class | Interface |
|---|---|---|
| 1 | Can have fields & constructors | No fields or constructors |
| 2 | Single inheritance | Multiple inheritance |
| 3 | Can have implemented methods | Only declarations (C# 8+ default) |
| 4 | Access modifiers allowed | All public by default |
| 5 | Share common code | Define contract |
| # | Delegate | Event |
|---|---|---|
| 1 | Type-safe function pointer | Wrapper over delegate |
| 2 | Can be invoked directly | Only publisher can raise |
| 3 | No encapsulation | Encapsulated |
| 4 | Used in LINQ, async | Used in GUI, notifications |
| 5 | Anyone can call | Only class can raise |
| # | Static Class | Singleton |
|---|---|---|
| 1 | No instance | One instance |
| 2 | Cannot inherit | Can inherit/implement |
| 3 | Hard to test | Easy to mock |
| 4 | Loaded at start | Lazy loading |
| 5 | No DI | Supports DI |
| # | ref | out |
|---|---|---|
| 1 | Must initialize before | No init required |
| 2 | Can read inside | Cannot read before assign |
| 3 | Optional assign | Must assign |
| 4 | Modify existing | Return new value |
| 5 | Two-way | Output-only |
| # | string | StringBuilder |
|---|---|---|
| 1 | Immutable | Mutable |
| 2 | New object on change | Same object |
| 3 | Slow in loops | Fast in loops |
| 4 | String pool | Dynamic buffer |
| 5 | Fixed text | Dynamic text |
| # | Boxing | Unboxing |
|---|---|---|
| 1 | Value → Object | Object → Value |
| 2 | Stack → Heap | Heap → Stack |
| 3 | Implicit | Explicit cast |
| 4 | Allocates memory | Copies value |
| 5 | Slower | Slower + exception risk |
| # | IEnumerable | IQueryable |
|---|---|---|
| 1 | In-memory | Database-side |
| 2 | LINQ to Objects | LINQ to SQL |
| 3 | Client execution | Server execution |
| 4 | Slower for big data | Faster (SQL) |
| 5 | List, Array | DbContext |
| # | Thread | Task |
|---|---|---|
| 1 | Low-level | High-level |
| 2 | OS managed | ThreadPool |
| 3 | Heavy | Lightweight |
| 4 | No async/await | Supports async |
| 5 | Manual control | Auto managed |
| # | const | readonly |
|---|---|---|
| 1 | Compile-time | Runtime |
| 2 | Primitives only | Any type |
| 3 | Implicit static | Can be instance |
| 4 | Never changes | Set in constructor |
| 5 | Substituted in IL | Stored in memory |
| # | == | .Equals() |
|---|---|---|
| 1 | Reference (default) | Value (if overridden) |
| 2 | Can overload | Can override |
| 3 | Fast | Slightly slower |
| 4 | String: content | String: content |
| 5 | Null safe | Risk of NullRef |
Answer: C# is a modern, object-oriented programming language developed by Microsoft. It runs on the .NET Framework and is designed to be simple, type-safe, and scalable. It combines the power of C/C++ with the ease of Java.
Use Case: Enterprise apps, desktop, web, mobile (Xamarin), cloud (Azure).
Answer: Visual Studio is Microsoft's IDE for developing, debugging, and deploying .NET applications. It supports C#, VB.NET, F#, and more.
Features: Code Editor, Debugger, IntelliSense, Designer, Compiler, Git Integration.
Answer: CLR is the execution engine of .NET. It manages code execution, memory, security, and garbage collection.
Key Roles: JIT Compilation, Exception Handling, Type Safety, GC.
| # | Value Type | Reference Type | Pointer Type |
|---|---|---|---|
| 1 | Stores value | Stores address | Stores memory address |
| 2 | Stack | Heap | Unsafe context |
| 3 | Copy on assign | Reference copy | Direct memory access |
| 4 | int, bool, struct | class, string, array | int*, char* |
| 5 | Fast, independent | Shared object | Rare, unsafe |
Categories:
| Type | Description | Example |
|---|---|---|
| Default | No params | public Person() {} |
| Parameterized | Takes input | public Person(string n) |
| Copy | Copies object | public Person(Person p) |
| Static | Runs once | static Person() {} |
| Private | Singleton | private Person() {} |
Answer: Destructor (~ClassName) is called by GC to clean up unmanaged resources. Implicitly invoked.
Note: Use IDisposable + Dispose() for deterministic cleanup.
| Generation | Purpose |
|---|---|
| Gen 0 | Short-lived (temp vars) |
| Gen 1 | Medium-lived |
| Gen 2 | Long-lived (static, cache) |
Dispose vs Finalize: Dispose = manual, Finalize = automatic by GC.
| Pillar | Description |
|---|---|
| Encapsulation | Data + Methods in class, hide internals |
| Abstraction | Show essential, hide complex |
| Inheritance | Reuse code via parent-child |
| Polymorphism | One name, many forms |
| # | Call by Value | Call by Reference |
|---|---|---|
| 1 | Copy passed | Address passed |
| 2 | No change to original | Original modified |
| 3 | Default | Use ref / out |
| # | Value Type | Reference Type |
|---|---|---|
| 1 | Stack | Heap |
| 2 | Copy on assign | Reference copy |
| 3 | struct, int | class, string |
| # | ref | out |
|---|---|---|
| 1 | Must initialize | No init needed |
| 2 | Can read | Cannot read before assign |
| 3 | Optional assign | Must assign |
| # | Abstract Class | Interface |
|---|---|---|
| 1 | Can have fields | No fields |
| 2 | Single inheritance | Multiple |
| 3 | Constructors | No constructors |
| # | Overloading | Overriding |
|---|---|---|
| 1 | Same class | Parent-child |
| 2 | Different params | Same signature |
| 3 | Compile-time | Runtime |
| # | Stack | Heap |
|---|---|---|
| 1 | Value types | Reference types |
| 2 | Fast, auto-clean | GC managed |
| 3 | Limited size | Large, dynamic |
| # | Managed | Unmanaged |
|---|---|---|
| 1 | CLR control | Direct OS |
| 2 | GC | Manual free |
| 3 | C# | C++, COM |
| # | Dispose | Finalize |
|---|---|---|
| 1 | Manual call | GC auto |
| 2 | IDisposable | ~Class() |
| 3 | Deterministic | Non-deterministic |