OOP & concepts

100 interview questions on ASP.NET, C#, SQL Server and OOP, with short answers

OOP & concepts · · Published 2026-10-29

These questions are the ones that recur in interviews for ASP.NET and SQL Server positions, from junior roles to experienced maintainers of Web Forms applications. The answers are deliberately short: they show what a good one-minute answer contains. Follow the links when a topic deserves a full explanation.

Answers refer to C# and .NET as currently documented by Microsoft. Where Web Forms (.NET Framework) and ASP.NET Core differ, the answer says so.

Object-oriented programming (1–15)

  1. What are the four pillars of OOP? Encapsulation, abstraction, inheritance and polymorphism. See OOP concepts with examples.
  2. Class vs object? A class is a type definition; an object is an instance of it created at run time.
  3. What is encapsulation? Hiding an object's state behind members that control access, typically private fields exposed through properties and methods.
  4. What is abstraction? Exposing what an object does while hiding how; abstract classes and interfaces are the language tools for it.
  5. What is inheritance? A class deriving from a base class to reuse and extend its members. C# allows one base class.
  6. What is polymorphism? One call behaving differently depending on the run-time type (overriding), or several signatures sharing a name (overloading).
  7. Overloading vs overriding? Overloading: same name, different parameters, resolved at compile time. Overriding: a derived class replaces a virtual or abstract member, resolved at run time.
  8. Abstract class vs interface? An abstract class can hold state, constructors and implemented members, and a class can inherit only one. A class can implement many interfaces; since C# 8 interfaces may have default implementations but still no instance fields.
  9. What does sealed do? Prevents a class from being inherited, or an override from being overridden further.
  10. What is a constructor? A method that initialises a new instance. A static constructor runs once per type, before first use.
  11. What is new as a member modifier? It hides an inherited member instead of overriding it; the base version is called through a base-typed reference.
  12. Access modifiers in C#? public, private, protected, internal, protected internal and private protected.
  13. What is composition? Building a class from other objects it holds, rather than inheriting from them. It is often preferred to deep inheritance.
  14. What are the SOLID principles? Single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion.
  15. Can C# do multiple inheritance? Not of classes. A class can implement several interfaces.

C# language (16–35)

  1. Value types vs reference types? Value types (int, struct, enum) hold their data and are copied on assignment; reference types (class, arrays, string) hold a reference to an object on the managed heap.
  2. What is boxing? Wrapping a value type in an object on the heap, for example when assigning an int to object. Unboxing reverses it with a cast.
  3. string vs String? The same type; string is the C# alias for System.String. Details.
  4. Why is string immutable, and when use StringBuilder? Every change creates a new string. Use StringBuilder when building text in a loop. Details.
  5. const vs readonly? const is a compile-time constant copied into callers; readonly fields are set at run time, in the declaration or a constructor.
  6. ref vs out? Both pass by reference. A ref argument must be initialised before the call; an out parameter must be assigned by the method.
  7. What is a delegate? A type-safe reference to a method. Func<> and Action<> are built-in generic delegates.
  8. What is an event? A delegate-based member that outside code can subscribe to but only the declaring class can raise.
  9. What are generics? Types and methods parameterised by type, giving type safety without boxing, such as List<T>.
  10. What is LINQ? Language-integrated query: query operators over collections, databases (through providers) and XML.
  11. IEnumerable<T> vs IQueryable<T>? IEnumerable runs queries in memory; IQueryable builds an expression tree a provider can translate, for example to SQL.
  12. What is deferred execution? A LINQ query runs when it is enumerated, not when it is declared.
  13. What does using do with an object? Calls Dispose() at the end of the block, even if an exception is thrown.
  14. Dispose vs finaliser? Dispose releases resources deterministically; a finaliser is a safety net run by the garbage collector at an unknown time.
  15. How does garbage collection work in .NET? A generational, tracing collector frees objects no longer reachable from roots; generations 0, 1 and 2 plus a large object heap.
  16. == vs Equals? For reference types == compares references unless overloaded (string overloads it to compare text); Equals can be overridden for value equality.
  17. What are async and await? Keywords that let a method wait for a task without blocking the thread; the compiler generates a state machine.
  18. What is a nullable value type? int?, shorthand for Nullable<int>, which can hold null.
  19. What is an extension method? A static method in a static class whose first parameter uses this, callable as if it were an instance method.
  20. throw vs throw ex? throw; rethrows and keeps the original stack trace; throw ex; resets it.

ASP.NET (36–60)

  1. What are the ASP.NET programming models? Web Forms, MVC and Web Pages on .NET Framework; ASP.NET Core adds Razor Pages, MVC, Blazor and minimal APIs. Overview.
  2. Describe the Web Forms page life cycle. PreInit, Init, InitComplete, PreLoad, Load, control events, LoadComplete, PreRender, SaveStateComplete, Render, Unload.
  3. What is a postback? A form submission back to the same page, after which ASP.NET restores state and raises control events.
  4. What does IsPostBack tell you? Whether the request is a postback; used to bind data only on the first load.
  5. What is ViewState? A hidden field storing control state between postbacks, base64-encoded and signed. ViewState vs Session.
  6. Where is Session state stored? InProc (default), StateServer, SQLServer or a custom provider. Out-of-process modes require serialisable objects; see the serialisation error.
  7. Session vs Application state? Session is per user; Application is shared by all users of the application.
  8. What is a cookie? A small name-value pair stored by the browser and sent with each request to the site.
  9. What is a QueryString? The part of a URL after ?, read with Request.QueryString. Example.
  10. Response.Redirect vs Server.Transfer? Redirect sends a 302 to the browser, which requests the new URL; Transfer switches pages on the server without a new request.
  11. What is cross-page posting? Posting a form to another page with PostBackUrl and reading the source through PreviousPage. Example.
  12. What is a master page? A template providing a common layout; content pages fill its ContentPlaceHolder regions.
  13. User control vs custom control? A user control is an .ascx file with markup; a custom control is a compiled class that renders its own output.
  14. What is web.config? The XML configuration file for an application: connection strings, app settings, authentication, modules and more.
  15. appSettings vs connectionStrings? Both hold key-value settings; connectionStrings adds a provider name and is read through ConfigurationManager.ConnectionStrings. Details.
  16. Authentication modes in Web Forms? Windows, Forms, and None (Passport is obsolete); ASP.NET Identity and OWIN cookies are used in newer apps.
  17. Authentication vs authorisation? Authentication establishes who the user is; authorisation decides what they may do.
  18. What is output caching? Storing the rendered output of a page or control for reuse, via @OutputCache.
  19. What are validation controls? RequiredFieldValidator, RangeValidator, RegularExpressionValidator, CompareValidator, CustomValidator, ValidationSummary. Always check Page.IsValid on the server.
  20. What does an UpdatePanel do? Performs a partial postback and refreshes only its content; the full page life cycle still runs on the server.
  21. GridView vs Repeater? GridView renders a table with built-in paging, sorting and editing; Repeater renders only your templates. Repeater example.
  22. Website vs web application project? A website compiles pages dynamically and has no project file; a web application project compiles to one assembly. Details.
  23. What is the Global.asax file? Handles application-level events such as Application_Start, Session_Start and Application_Error.
  24. HTTP handler vs HTTP module? A handler produces the response for a request type; a module plugs into every request's pipeline events.
  25. What is MVC? Model-View-Controller: controllers handle requests, models hold data and rules, views render output. Routing maps URLs to actions.

ADO.NET (61–70)

  1. Core ADO.NET objects? Connection, Command, DataReader, DataAdapter, DataSet, DataTable, Parameter, Transaction.
  2. ExecuteReader, ExecuteNonQuery, ExecuteScalar? Rows, affected-row count, single value. Details.
  3. DataReader vs DataSet? A DataReader is a forward-only, read-only stream on an open connection; a DataSet is a disconnected in-memory copy. Details.
  4. DataSet vs DataTable? A DataTable is one table; a DataSet holds several tables and their relations. Details.
  5. What does a DataAdapter do? Fills a DataSet or DataTable with Fill and pushes changes back with Update.
  6. What is connection pooling? Reusing physical connections for identical connection strings; Close returns a connection to the pool.
  7. Why use parameters? To prevent SQL injection and let SQL Server reuse plans.
  8. How do you run a transaction? BeginTransaction on the connection, assign it to commands, then Commit or Rollback; or use TransactionScope.
  9. What is a table-valued parameter? A way to pass a set of rows to a stored procedure in one call. Example.
  10. What is SqlBulkCopy? A class that loads large numbers of rows into a SQL Server table efficiently.

SQL Server (71–88)

  1. Primary key vs unique key? Both enforce uniqueness; a table has one primary key, which cannot contain NULL, and may have several unique constraints, which allow one NULL each in SQL Server.
  2. What is a foreign key? A constraint making a column's values match a key in another table.
  3. Clustered vs non-clustered index? A clustered index defines the physical order of the table rows (one per table); non-clustered indexes are separate structures pointing to rows.
  4. DELETE vs TRUNCATE? DELETE removes rows one by one, can filter and fires triggers; TRUNCATE deallocates all pages, resets identity, cannot have WHERE.
  5. WHERE vs HAVING? WHERE filters rows before grouping; HAVING filters groups after GROUP BY.
  6. Types of joins? INNER, LEFT/RIGHT/FULL OUTER, CROSS, plus self joins and APPLY.
  7. UNION vs UNION ALL? UNION removes duplicates; UNION ALL keeps them and is faster.
  8. Stored procedure vs function? A procedure can modify data and return several result sets; a function returns a value or table and can be used in queries but cannot change database state.
  9. What is a view? A saved SELECT that behaves like a virtual table.
  10. What is a trigger? Code that runs automatically after or instead of INSERT, UPDATE or DELETE on a table or view.
  11. What is normalisation? Organising tables to remove redundancy: 1NF, 2NF, 3NF and beyond.
  12. What are ACID properties? Atomicity, consistency, isolation, durability.
  13. Isolation levels? Read uncommitted, read committed (default), repeatable read, serializable, snapshot; plus the read committed snapshot option.
  14. @@IDENTITY vs SCOPE_IDENTITY()? SCOPE_IDENTITY() returns the last identity in the current scope, ignoring values generated by triggers; prefer it, or an OUTPUT clause.
  15. Temporary table vs table variable? #temp tables live in tempdb, support indexes and statistics; @table variables are scoped to the batch with limited statistics.
  16. What is a CTE? A common table expression, a named result defined with WITH for one statement; it can be recursive.
  17. ROW_NUMBER, RANK, DENSE_RANK? Window functions numbering rows: unique numbers, ranks with gaps after ties, ranks without gaps.
  18. How do you page results? ORDER BY … OFFSET n ROWS FETCH NEXT m ROWS ONLY (SQL Server 2012 and later).

Web basics and security (89–100)

  1. GET vs POST? GET puts data in the URL and should not change state; POST sends it in the body.
  2. Common HTTP status codes? 200 OK, 301/302 redirects, 304 Not Modified, 400, 401, 403, 404, 500, 503.
  3. What is AJAX? Requests made from script without reloading the page. Calling a page method with jQuery.
  4. What is JSON? A text format for structured data based on JavaScript object syntax.
  5. What is XSS? Cross-site scripting: injecting script into pages other users see. Encode output with HttpUtility.HtmlEncode or <%: %>.
  6. What is request validation? Web Forms rejects input that looks like HTML; see the "potentially dangerous" error.
  7. What is CSRF? Cross-site request forgery, a forged request riding on a user's cookies; mitigated with anti-forgery tokens and SameSite cookies.
  8. How should passwords be stored? As salted hashes from a slow algorithm (PBKDF2, bcrypt, Argon2), never encrypted or plain.
  9. What is HTTPS for? Encrypting and authenticating traffic with TLS.
  10. What is the jQuery $(document).ready handler? Code run once the DOM is parsed; $(function(){…}) is shorthand.
  11. What is the difference between == and === in JavaScript? == converts types before comparing; === does not.
  12. Java vs .NET? Both are managed platforms with a VM, garbage collection and large libraries. Comparison.

Official documentation