# C# / OOP Interview Cheat Sheet (Quick Revision)
---
## 1. const vs readonly vs static
- const → compile-time constant, must assign at declaration.
- readonly → runtime constant, assignable in constructor.
- static → belongs to class, shared across all objects.
Tricky: static readonly is allowed → single shared, set once.
---
## 2. abstract class vs interface
- abstract → can have abstract + implemented methods, single inheritance.
- interface → contract only, multiple inheritance allowed.
Tricky Q: Can abstract class have constructor? → Yes.
---
## 3. overloading vs overriding
- Overloading → same method, different params (compile-time).
- Overriding → same signature, redefined in child class (runtime).
Tricky Q: Can both exist together? → Yes.
---
## 4. sealed
- sealed class → cannot be inherited.
- sealed override → prevents further overriding.
---
## 5. static
- static class → cannot be instantiated or inherit.
- static constructor → no params, runs once automatically.
---
## 6. Inheritance
Q: Why multiple inheritance not allowed? → To avoid diamond problem.
---
## 7. Polymorphism
- virtual → has default implementation, can be overridden.
- abstract → no implementation, must override.
Tricky: Calling non-virtual → hides base method.
---
## 8. Garbage Collection
- Dispose() → manual cleanup, called by dev.
- Finalize() → automatic by GC.
---
## 9. String
- string is immutable.
- StringBuilder → mutable, better for changes.
---
## 10. Exception Handling
Tricky: finally can be skipped if process terminates.
---
## 11. Equality
- == → compares reference for objects (unless overloaded).
- .Equals() → can compare values.
---
## 12. Delegates & Events
- delegate → function pointer.
- event → pub-sub wrapper over delegate.
---
## 13. LINQ
- Deferred execution → query runs only when iterated.
---
## 14. Threads & Tasks
- Thread.Sleep() → blocks thread.
- Task.Delay() → async, non-blocking.
---
## 15. Reflection
- Inspect metadata at runtime (types, methods).
---
## 16. Generics
- Type-safe reusable code, avoids boxing/unboxing.
---
## 17. dynamic vs var
- var → compile-time type checking.
- dynamic → runtime, slower.
---
## 18. Access Modifiers
- protected → derived classes.
- internal → same assembly.
- protected internal → either.
---
## 19. Boxing & Unboxing
- Boxing → value → object.
- Unboxing → object → value.
Costly because of type check + allocation.
---
## 20. General C# Tricky
- async Main() allowed since C# 7.1.
- Multiple Main() allowed but one is entry point.
- Private constructor → Singleton pattern.