0% found this document useful (0 votes)
30 views3 pages

Dotnet Interview Prep

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views3 pages

Dotnet Interview Prep

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C# / .

NET Developer Interview Preparation

C# / .NET Core Fundamentals


Q: Difference between value type and reference type
A: Value types store data directly in memory (e.g., int, struct). Reference types store a reference to the data (e.g.,
class, string). Value types are stored in stack, reference types in heap.
Q: Boxing and Unboxing
A: Boxing is converting a value type to object (or reference type). Unboxing is extracting the value type from the object.
Boxing is implicit, unboxing is explicit.
Q: Difference between == and .Equals()
A: == compares references for reference types, and actual values for value types. .Equals() checks for value equality
(and can be overridden in classes).
Q: Generics
A: Generics allow defining classes, methods, and collections with placeholders for types (e.g., List). They improve type
safety and performance by avoiding boxing/unboxing.
Q: Delegates, Func, Action, Predicate
A: Delegate is a type-safe function pointer. Func returns a value, Action returns void, Predicate returns a boolean.
Q: Abstract class vs Interface
A: Abstract class: can have fields, constructors, access modifiers, and abstract/virtual methods. Interface: only
method/property/event/indexer declarations, no implementation (till C# 8 default methods).
Q: Method hiding vs overriding
A: Hiding uses 'new' keyword, overriding uses 'override'. Hiding replaces the method in child only, overriding modifies
base behavior polymorphically.
Q: Extension methods
A: Allow adding new methods to existing types without modifying their code, using static methods in static classes.
Q: LINQ
A: Language Integrated Query provides a consistent query syntax (SQL-like) to query objects, collections, XML, and
databases.
Q: async / await
A: Async allows non-blocking execution. Await releases the thread until the task completes. Improves responsiveness
in apps.
Q: IEnumerable vs ICollection vs IList vs IQueryable
A: IEnumerable: forward-only iteration. ICollection: adds Count, Add, Remove. IList: index-based access. IQueryable:
supports LINQ-to-database queries with deferred execution.

ASP.NET / Web API


Q: REST vs SOAP
A: REST uses HTTP, JSON/XML, stateless. SOAP uses XML, strict standards, more overhead.
Q: Dependency Injection
A: Technique to achieve Inversion of Control. In ASP.NET Core, services are registered in Startup.cs (AddTransient,
AddScoped, AddSingleton) and injected via constructor.
Q: Middleware
A: Components in request pipeline that handle requests/responses (e.g., authentication, logging). Registered in
Startup.cs using app.UseMiddleware().
Q: Authentication vs Authorization
A: Authentication: verifying identity (e.g., login). Authorization: determining access rights (e.g., roles, claims).
Q: HTTP verbs
A: GET = fetch data, POST = create, PUT = update, DELETE = remove.
Q: Exception handling
A: Use try-catch, global exception middleware, or filters. Can return ProblemDetails for consistent API errors.
Q: Configuration security
A: Use user-secrets, environment variables, or Azure Key Vault instead of storing plain text connection strings.

SQL & EF Core


Q: Second highest salary query
A: SELECT MAX(Salary) FROM Employees WHERE Salary < (SELECT MAX(Salary) FROM Employees);
Q: INNER vs LEFT vs RIGHT vs FULL JOIN
A: INNER: matching rows only. LEFT: all left + matches. RIGHT: all right + matches. FULL: all rows from both sides.
Q: Performance improvement
A: Use indexes, avoid SELECT *, normalize data, use proper joins, analyze execution plan.
Q: Stored Procedure vs Function
A: SP: can have multiple statements, return 0 or many values, support transactions. Function: must return a value, can
be used in SELECT.
Q: EF Core Loading
A: Lazy = load on access, Eager = load with main query, Explicit = manually call Load().
Q: FirstOrDefault vs SingleOrDefault vs Find
A: FirstOrDefault: returns first or null. SingleOrDefault: expects only one element. Find: searches by primary key using
context cache.

OOPS & Design Patterns


Q: 4 pillars of OOPS
A: Encapsulation, Abstraction, Inheritance, Polymorphism.
Q: Singleton pattern
A: Ensures only one instance of a class exists. Example: Logger, ConfigurationManager. Implemented with private
constructor + static instance.
Q: Factory vs Abstract Factory
A: Factory creates objects without specifying exact class. Abstract Factory provides interface to create families of
related objects.
Q: Observer pattern
A: Defines one-to-many dependency between objects. In C#, events and delegates implement observer pattern.
Q: Repository pattern
A: Abstracts data access logic. Central place for CRUD operations, improves testability and separation of concerns.

Coding / Problem Solving


Q: Reverse a string
A: Iterate from end to start, build new string. Or use char array and reverse it.
Q: Palindrome check
A: Compare string with its reverse, or two pointers from start/end.
Q: First non-repeated character
A: Use dictionary to count occurrences, return first with count=1.
Q: Remove duplicate characters
A: Use HashSet to track seen characters while building result string.
Q: Array rotation
A: Left rotation: move first d elements to end. Right rotation: move last d elements to start.
Q: Majority element
A: Boyer-Moore voting algorithm (element that appears > n/2 times).
Q: Fibonacci series
A: Recursion: f(n)=f(n-1)+f(n-2). Iterative: loop storing previous two numbers.
Q: Stack & Queue
A: Stack = LIFO, implemented with array/list + push/pop. Queue = FIFO, implemented with array/list +
enqueue/dequeue.
Q: Anagram check
A: Two strings are anagrams if sorted characters are same or char counts match.

You might also like