Frequently Asked Questions (FAQ)
❓ FAQ: Intermediate C# Concepts
🔹 Q1: When should I use an interface vs abstract class?
Use interfaces for defining capabilities (e.g., IDrawable
) across unrelated types. Use abstract classes when you want to provide a shared base with some default implementation.
🔹 Q2: How is LINQ different from SQL?
LINQ provides SQL-like querying for in-memory collections (like arrays, lists). It's strongly typed, integrated into C#, and checked at compile-time.
🔹 Q3: What’s the difference between Task
, Thread
, and async
?
Task
is a unit of asynchronous work.Thread
is a lower-level OS-managed thread.async
methods useTask
to manage background operations without blocking.
🔹 Q4: How do delegates improve flexibility?
Delegates allow you to pass behavior (methods) as parameters, enabling loose coupling and callbacks, essential for building reusable libraries and UI frameworks.
🔹 Q5: Are records better than classes?
Records are optimized for immutable data containers and value equality (e.g., DTOs). Use classes when you need mutability or inheritance.