C# .Net Fundamentals interview questions

 

1. Basic .NET Concepts

  1. What is the .NET Framework?

    • A software framework by Microsoft that provides a runtime (CLR) and libraries for building applications.

  2. What is CLR (Common Language Runtime)?

    • The execution engine that manages memory, security, and exception handling for .NET applications.

  3. What is CTS (Common Type System) and CLS (Common Language Specification)?

    • CTS defines data types across .NET languages.

    • CLS ensures language interoperability by defining rules.

  4. What is Managed vs Unmanaged Code?

    • Managed code runs under CLR control (e.g., C#).

    • Unmanaged code runs outside CLR (e.g., C++ native code).


2. C# Fundamentals

  1. What are the main differences between C# and Java?

    • C# has properties, delegates, events, and structs (value types), while Java relies more on interfaces.

  2. What is boxing and unboxing?

    • Boxing: Converting a value type to an object (e.g., int to object).

    • Unboxing: Converting an object back to a value type.

  3. What is the difference between == and .Equals()?

    • == compares references (for objects) or values (for primitives).

    • .Equals() compares content (can be overridden).

  4. What are value types vs reference types?

    • Value types (intstruct) store data directly.

    • Reference types (classstring) store memory references.


3. OOP Concepts

  1. What are the four pillars of OOP?

    • EncapsulationInheritancePolymorphismAbstraction.

  2. What is the difference between abstract class and interface?

    • Abstract class can have method implementations; interface cannot (until C# 8.0).

    • A class can inherit only one abstract class but multiple interfaces.

  3. What is method overloading vs overriding?

    • Overloading: Same method name, different parameters (compile-time).

    • Overriding: Redefining a method in a derived class (runtime, using virtual/override).


4. Memory Management & Garbage Collection

  1. What is Garbage Collection (GC) in .NET?

    • Automatic memory management by CLR that reclaims unused objects.

  2. What are generations in GC (Gen 0, Gen 1, Gen 2)?

    • Objects are promoted through generations based on lifespan (Gen 0 = short-lived, Gen 2 = long-lived).

  3. What is the IDisposable interface?

    • Used to release unmanaged resources (e.g., file handles) via the Dispose() method.

  4. What is the using statement in C#?

    • Ensures Dispose() is called automatically (syntactic sugar for try-finally).


5. Asynchronous Programming

  1. What is the difference between Task and Thread?

    • Thread is a low-level OS construct.

    • Task is a higher-level abstraction for async operations (uses thread pool).

  2. What are async and await?

    • async marks a method as asynchronous.

    • await pauses execution until the task completes.

  3. What is deadlock in async programming?

    • Occurs when two tasks wait indefinitely for each other (e.g., due to .Result or .Wait() misuse).


6. ASP.NET & Web APIs

  1. What is the difference between ASP.NET MVC and Web API?

    • MVC returns views (HTML), Web API returns data (JSON/XML).

  2. What is Middleware in ASP.NET Core?

    • Components that handle requests/responses (e.g., authentication, logging).

  3. What is Dependency Injection (DI)?

    • A design pattern where dependencies are injected rather than created inside a class.

  4. What is JWT (JSON Web Token)?

    • A token-based authentication mechanism used in APIs.


7. Entity Framework (ORM)

  1. What is Entity Framework?

    • An ORM (Object-Relational Mapper) for database operations using C# objects.

  2. What is the difference between IQueryable and IEnumerable?

    • IQueryable executes queries on the database.

    • IEnumerable executes queries in memory.

  3. What are LINQ and its types (Query vs Method Syntax)?

    • LINQ (Language Integrated Query) allows querying collections.

    • Query Syntax: SQL-like (e.g., from x in list select x).

    • Method Syntax: Fluent (e.g., list.Where(x => x > 5)).


8. Advanced Topics

  1. What is Reflection in .NET?

    • Inspecting types/metadata at runtime (e.g., typeof()GetMethod()).

  2. What is a Delegate and an Event?

    • Delegate: A type-safe function pointer.

    • Event: A mechanism for notification (uses delegates).

  3. What is Dependency Injection (DI) in .NET Core?

    • Built-in IoC container for managing object lifetimes (e.g., AddScopedAddSingleton).

  4. What is SignalR?

    • A library for real-time web functionality (e.g., chat apps).

  5. What is .NET Core vs .NET Framework vs .NET 5/6/7/8?

    • .NET Framework: Windows-only.

    • .NET Core: Cross-platform, open-source.

    • .NET 5+: Unified platform (successor to both).


Final Tips

  • Be ready for coding challenges (e.g., reverse a string, Fibonacci series).

  • Know design patterns (Singleton, Factory, Repository).

  • Understand REST principles if applying for API roles.

  • Practice Entity Framework queries and performance tuning.

No comments:

Post a Comment

Best for you