ASP.NET

  1. What is the ASP.NET page life cycle?
    • Answer: The ASP.NET page life cycle includes stages like initialization, loading, postback handling, rendering, and unloading. Key events include Page_Init, Page_Load, Page_PreRender, and Page_Unload.
  2. Describe the ASP.NET MVC pattern.
    • Answer: ASP.NET MVC separates an application into three main components: Model (data), View (UI), and Controller (business logic). This separation of concerns facilitates easier management, testing, and scaling of applications.
  3. What are the main differences between ASP.NET Web Forms and ASP.NET MVC?
    • Answer: Web Forms use a drag-and-drop, event-driven model, while MVC uses a stateless, lightweight model that separates concerns. MVC offers more control over HTML and better support for TDD.
  4. How do you manage state in an ASP.NET application?
    • Answer: State can be managed using ViewState, Session State, Application State, Cookies, and Query Strings.
  5. What are HttpHandlers and HttpModules?
    • Answer: HttpHandlers process individual HTTP requests, while HttpModules are invoked on every request and can modify the request/response pipeline.
  6. Explain the role of Global.asax in an ASP.NET application.
    • Answer: Global.asax is used to handle application-level events such as Application_Start, Application_End, Session_Start, and Session_End.
  7. What is the difference between Server.Transfer and Response.Redirect?
    • Answer: Server.Transfer transfers request processing to another page on the server without making a round trip to the client, while Response.Redirect sends a response to the client to request a new page, causing a round trip.
  8. How does ASP.NET handle sessions?
    • Answer: ASP.NET handles sessions using a unique session ID stored in a cookie or URL. Session data can be stored in-process, out-of-process, or in a SQL Server.
  9. Explain the concept of ViewState in ASP.NET.
    • Answer: ViewState is used to persist the state of web controls between postbacks. It is stored in a hidden field on the page.
  10. What is Razor, and how is it used in ASP.NET?
    • Answer: Razor is a view engine in ASP.NET that allows for embedding server-based code (C# or VB.NET) into web pages using a simple syntax (@).
  11. What is Web API, and how does it differ from WCF?
    • Answer: Web API is used to create RESTful services over HTTP, whereas WCF supports multiple protocols (HTTP, TCP, MSMQ) and can be used for building more complex, service-oriented applications.
  12. How do you implement authentication and authorization in ASP.NET?
    • Answer: Authentication can be implemented using forms authentication, Windows authentication, or OAuth. Authorization can be role-based, using attributes like [Authorize].
  13. What is Dependency Injection, and how is it used in ASP.NET Core?
    • Answer: Dependency Injection (DI) is a design pattern for managing dependencies. ASP.NET Core has built-in DI, allowing services to be injected into controllers and other services.
  14. What is the purpose of the web.config file in an ASP.NET application?
    • Answer: The web.config file is used to configure application settings, database connections, session states, error handling, security, and more.
  15. Explain the concept of routing in ASP.NET MVC.
    • Answer: Routing in ASP.NET MVC maps URL patterns to controller actions. It is defined in the RouteConfig.cs file using RouteCollection.
  16. What is the difference between TempData, ViewData, and ViewBag?
    • Answer: ViewData and ViewBag are used to pass data from the controller to the view. TempData is used to pass data between two requests.
  17. How do you handle exceptions in ASP.NET MVC?
    • Answer: Exceptions can be handled using try-catch blocks, custom error pages, the HandleError attribute, or middleware for global exception handling in ASP.NET Core.
  18. What are Bundling and Minification in ASP.NET?
    • Answer: Bundling combines multiple files into one, while minification reduces the size of files by removing unnecessary characters. This improves page load performance.
  19. What is SignalR, and how is it used in ASP.NET?
    • Answer: SignalR is a library for adding real-time web functionality to applications, allowing server-side code to push content to connected clients instantly.
  20. What is Entity Framework, and how is it used in ASP.NET?
    • Answer: Entity Framework (EF) is an ORM framework for .NET, allowing developers to work with databases using .NET objects. It supports LINQ queries, change tracking, and schema migrations.

C#

  1. What is the difference between value types and reference types in C#?
    • Answer: Value types (e.g., int, struct) are stored on the stack and contain their data directly. Reference types (e.g., class, array) are stored on the heap, and variables hold references to their data.
  2. What are public, private, protected, and internal access modifiers?
    • Answer: public allows access from any code, private restricts access to the containing class, protected allows access within the containing class and derived classes, and internal restricts access to the same assembly.
  3. Explain the concept of null in C#.
    • Answer: null is a literal that represents a null reference, indicating that a variable does not refer to any object.
  4. What is LINQ, and how is it used in C#?
    • Answer: LINQ (Language Integrated Query) is used to query collections, databases, XML, and more using a uniform syntax integrated into C#. Examples include LINQ to Objects, LINQ to SQL, and LINQ to XML.
  5. How do you implement exception handling in C#?
    • Answer: Exception handling is implemented using try, catch, finally, and throw keywords. Custom exceptions can be created by inheriting from the Exception class.
  6. What is the async and await pattern in C#?
    • Answer: async and await are used for asynchronous programming. async modifies a method to indicate it contains asynchronous operations, while await pauses the method execution until the awaited task completes.
  7. What are delegates and events in C#?
    • Answer: Delegates are type-safe pointers to methods, and events are a way to notify subscribers when something occurs. Delegates are used to declare events.
  8. What is the difference between an abstract class and an interface in C#?
    • Answer: An abstract class can have implementations and state, while an interface can only declare methods and properties without implementations. Classes can inherit multiple interfaces but only one abstract class.
  9. Explain the SOLID principles in C#.
    • Answer: SOLID principles are guidelines for designing software: Single Responsibility Principle, Open/Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle.
  10. What are generics in C#, and why are they useful?
    • Answer: Generics allow the creation of type-safe classes, methods, and structures. They enable code reusability and type safety without boxing/unboxing overhead.
  11. How does garbage collection work in .NET?
    • Answer: Garbage collection automatically manages memory by freeing objects that are no longer in use. The .NET garbage collector uses a generational approach (0, 1, and 2) to optimize performance.
  12. What is the difference between String and StringBuilder in C#?
    • Answer: String is immutable, meaning its value cannot be changed after creation. StringBuilder is mutable and allows for efficient manipulation of strings.
  13. Explain the use of the using statement in C#.
    • Answer: The using statement ensures that resources are disposed of properly. It is commonly used with IDisposable objects like file streams and database connections.
  14. What are lambda expressions in C#?
    • Answer: Lambda expressions are anonymous functions that can contain expressions and statements. They are used with delegates or expression trees and provide a concise syntax for writing inline functions.
  15. What is an extension method in C#?
    • Answer: Extension methods allow adding new methods to existing types without modifying their source code. They are static methods defined in static classes, with the first parameter preceded by this keyword.
  16. What is the purpose of yield in C#?
    • Answer: The yield keyword is used in an iterator block to return each element one at a time, enabling the creation of custom enumerators without creating a temporary collection.
  17. Explain the concept of reflection in C#.
    • Answer: Reflection allows inspection of metadata about types at runtime, including accessing type information, creating instances, and invoking methods. It is used for tasks like dynamic type discovery and late binding.
  18. What is the difference between const and readonly in C#?
    • Answer: const variables are compile-time constants and cannot be changed. readonly fields can be assigned at declaration or in a constructor, allowing for runtime constants.
  19. How do you implement a singleton pattern in C#?
    • Answer: A singleton ensures a class has only one instance and provides a global access point to it. This is implemented by creating a private static instance, a private constructor, and a public static property.
  20. What are nullable types in C#?
    • Answer: Nullable types allow value types to represent null values. They are declared using ?, e.g., int?, and are useful for database operations and other scenarios where a value type may not have a value.

SQL Server

  1. What are the different types of joins in SQL Server?
    • Answer: Types of joins include INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and CROSS JOIN.
  2. Explain the concept of indexing in SQL Server.
    • Answer: Indexes improve the speed of data retrieval. There are clustered and non-clustered indexes. Clustered indexes determine the physical order of data, while non-clustered indexes create a separate structure for data lookup.
  3. How do you optimize a SQL query?
    • Answer: Query optimization involves indexing, avoiding unnecessary columns in SELECT statements, using joins instead of subqueries, and analysing execution plans.
  4. What is the difference between a primary key and a unique key?
    • Answer: A primary key uniquely identifies each record and does not allow nulls. A unique key also enforces uniqueness but allows a single null value.
  5. How do you handle transactions in SQL Server?
    • Answer: Transactions ensure that a series of operations are completed successfully or not at all, using BEGIN TRANSACTION, COMMIT, and ROLLBACK.
  6. What are stored procedures and functions in SQL Server?
    • Answer: Stored procedures are precompiled collections of SQL statements, while functions are routines that return a value. Functions can be scalar or table-valued.
  7. What is normalization, and why is it important in database design?
    • Answer: Normalization reduces data redundancy and improves data integrity by organizing tables according to normal forms (1NF, 2NF, 3NF, etc.).
  8. How do you use the GROUP BY clause in SQL Server?
    • Answer: The GROUP BY clause groups rows that have the same values in specified columns and allows aggregate functions like SUM, COUNT, AVG, etc., to be applied.
  9. What are triggers in SQL Server?
    • Answer: Triggers are special stored procedures that automatically execute in response to specific events on a table or view, such as INSERT, UPDATE, or DELETE.
  10. How do you implement error handling in SQL Server?
    • Answer: Error handling in SQL Server is done using TRY…CATCH blocks. Errors are caught and handled within the CATCH block, and details can be retrieved using functions like ERROR_MESSAGE().
  11. What is the difference between DELETE and TRUNCATE?
    • Answer: DELETE removes rows based on a condition and logs individual row deletions. TRUNCATE removes all rows in a table without logging individual row deletions, making it faster but less flexible.
  12. Explain the ACID properties of a transaction.
    • Answer: ACID properties ensure reliable transactions: Atomicity (all or nothing), Consistency (valid state), Isolation (independent transactions), and Durability (permanent changes).
  13. What are constraints in SQL Server?
    • Answer: Constraints enforce rules at the table level, including PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and DEFAULT.
  14. What is a CTE (Common Table Expression) in SQL Server?
    • Answer: A CTE is a temporary result set defined within the execution scope of a single SELECT, INSERT, UPDATE, or DELETE statement. It is defined using the WITH clause.
  15. How do you implement paging in SQL Server?
    • Answer: Paging can be implemented using the OFFSET and FETCH NEXT clauses in a SELECT statement to retrieve a subset of rows.
  16. What is the difference between HAVING and WHERE?
    • Answer: WHERE filters rows before grouping, while HAVING filters groups after the GROUP BY clause is applied.
  17. How do you create a backup and restore a database in SQL Server?
    • Answer: Backups can be created using the BACKUP DATABASE command, and databases can be restored using the RESTORE DATABASE command.
  18. What is SQL injection, and how can it be prevented?
    • Answer: SQL injection is a code injection technique that exploits vulnerabilities in a SQL query. It can be prevented by using parameterized queries, stored procedures, and proper input validation.
  19. What are the different isolation levels in SQL Server?
    • Answer: Isolation levels control the visibility of changes made by one transaction to other transactions. They include Read Uncommitted, Read Committed, Repeatable Read, Serializable, and Snapshot.
  20. What is the difference between a temporary table and a table variable?
    • Answer: Temporary tables (#TempTable) are stored in the tempdb database and can be indexed. Table variables (@TableVar) are stored in memory and have limited scope and indexing capabilities.

ASP.NET

  1. What is the difference between Web.config and Machine.config?
    • Answer: Web.config is application-specific, while Machine.config applies to all applications on the server. Machine.config defines default configuration settings.
  2. What is the purpose of the ViewBag in ASP.NET MVC?
    • Answer: ViewBag is a dynamic object used to pass data from the controller to the view. It is a convenient way to share data without using strongly-typed views.
  3. How do you perform validation in ASP.NET MVC?
    • Answer: Validation can be performed using data annotations, model state validation, and custom validation attributes. Client-side validation can be enabled using jQuery validation.
  4. What is the difference between synchronous and asynchronous methods in ASP.NET?
    • Answer: Synchronous methods block the thread until the operation completes, while asynchronous methods allow the thread to continue processing other tasks, improving scalability.
  5. What are action filters in ASP.NET MVC?
    • Answer: Action filters are attributes that can be applied to controllers or actions to perform pre- or post-processing logic. Examples include Authorize, HandleError, and OutputCache.
  6. What is the purpose of the RouteConfig.cs file in an ASP.NET MVC application?
    • Answer: RouteConfig.cs defines URL routing rules, mapping URL patterns to controller actions. It is used to configure how requests are routed within the application.
  7. What is the difference between TempData and Session in ASP.NET MVC?
    • Answer: TempData is used to store data temporarily and is available for the next request only. Session persists data across multiple requests and user sessions.
  8. How do you enable caching in ASP.NET MVC?
    • Answer: Caching can be enabled using the OutputCache attribute on controllers or actions. It caches the output of responses to improve performance.
  9. What are model binders in ASP.NET MVC?
    • Answer: Model binders map HTTP request data to action method parameters. Custom model binders can be created to handle complex data binding scenarios.
  10. What is OWIN, and how is it related to ASP.NET?
    • Answer: OWIN (Open Web Interface for .NET) defines a standard interface between web servers and web applications. It decouples the application from the server, allowing for more flexible hosting options.

C#

  1. What is the difference between var and dynamic in C#?
    • Answer: var is a statically-typed variable inferred at compile-time, while dynamic is a dynamically-typed variable resolved at runtime, allowing for more flexible operations.
  2. What is a sealed class in C#?
    • Answer: A sealed class cannot be inherited. It is used to prevent further derivation and to optimize performance by the compiler.
  3. What is the difference between == and Equals() in C#?
    • Answer: == checks for reference equality for reference types and value equality for value types. Equals() checks for value equality and can be overridden to provide custom comparison logic.
  4. Explain the use of the lock statement in C#.
    • Answer: The lock statement ensures that a block of code runs exclusively, preventing multiple threads from accessing shared resources simultaneously and causing race conditions.
  5. What are partial classes in C#?
    • Answer: Partial classes allow the definition of a class to be split across multiple files. This enables better organization and collaborative development.
  6. What is an anonymous type in C#?
    • Answer: Anonymous types are created using the new keyword without specifying a type name. They are used to encapsulate a set of read-only properties into a single object.
  7. What are tuples in C#?
    • Answer: Tuples are data structures that group multiple values into a single unit. They can be used to return multiple values from a method without using out parameters.
  8. Explain the concept of covariance and contravariance in C#.
    • Answer: Covariance allows a method to return a more derived type than specified, while contravariance allows a method to accept parameters of less derived types.
  9. What is an expression tree in C#?
    • Answer: Expression trees represent code in a tree-like data structure, allowing for dynamic modification and execution of expressions at runtime. They are used in LINQ for building dynamic queries.
  10. How do you handle null values in C#?
    • Answer: Null values can be handled using the null-coalescing operator (??), null-conditional operator (?.), or checking for null explicitly with an if statement.

SQL Server

  1. What is database normalization and denormalization?
    • Answer: Normalization organizes data to reduce redundancy and improve integrity, while denormalization combines tables to improve query performance at the expense of redundancy.
  2. What is a stored procedure in SQL Server?
    • Answer: A stored procedure is a precompiled collection of SQL statements and optional control-of-flow statements stored under a name and processed as a unit.
  3. What is a cursor in SQL Server?
    • Answer: A cursor is a database object used to retrieve, manipulate, and navigate through a result set row by row. Cursors are used when row-by-row operations are necessary.
  4. What is the difference between a clustered index and a non-clustered index?
    • Answer: A clustered index determines the physical order of data in a table and can only be one per table. A non-clustered index creates a separate structure for the index and can be multiple per table.
  5. What are the different types of constraints in SQL Server?
    • Answer: Constraints include PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK, and DEFAULT. They enforce rules to maintain data integrity.
  6. What is a view in SQL Server?
    • Answer: A view is a virtual table based on the result of a SELECT query. Views simplify complex queries, provide security by restricting data access, and can improve performance in certain scenarios.
  7. How do you use the CASE statement in SQL Server?
    • Answer: The CASE statement provides conditional logic within SQL queries, allowing different values to be returned based on specified conditions.
  8. What is a subquery, and how is it used in SQL Server?
    • Answer: A subquery is a query nested within another query. Subqueries can be used in SELECT, INSERT, UPDATE, and DELETE statements to perform more complex data retrieval and manipulation.
  9. What is a transaction log in SQL Server?
    • Answer: The transaction log records all transactions and database modifications to ensure data integrity and support recovery operations in case of failure.
  10. What is a deadlock in SQL Server, and how do you resolve it?
    • Answer: A deadlock occurs when two or more transactions block each other by holding locks on resources the other transactions need. Resolving deadlocks involves deadlock detection, avoidance, and using techniques like increasing lock granularity and minimizing transaction time.
  11. What are the different recovery models in SQL Server?
    • Answer: Recovery models determine how transactions are logged and how the database can be restored. The models are Simple, Full, and Bulk-logged.
  12. How do you use TRY…CATCH for error handling in SQL Server?
    • Answer: TRY…CATCH blocks are used to handle errors gracefully. Code in the TRY block is executed, and if an error occurs, control is passed to the CATCH block to handle the error.
  13. What is SQL Server Agent, and what is it used for?
    • Answer: SQL Server Agent is a component for automating administrative tasks, such as scheduling jobs, alerts, and executing scripts.
  14. How do you create and use a user-defined function (UDF) in SQL Server?
    • Answer: UDFs are custom functions written in T-SQL that return a scalar value or a table. They are created using the CREATE FUNCTION statement and can be used in queries to encapsulate reusable logic.
  15. What is the difference between INNER JOIN and OUTER JOIN?
    • Answer: INNER JOIN returns only the matching rows from both tables, while OUTER JOIN (LEFT, RIGHT, FULL) returns all rows from one or both tables, including non-matching rows with NULL values.
  16. What is SQL Profiler, and how is it used?
    • Answer: SQL Profiler is a tool for monitoring and analysing SQL Server events. It is used for debugging, performance tuning, and auditing.
  17. What is the purpose of the ALTER statement in SQL Server?
    • Answer: The ALTER statement is used to modify the structure of existing database objects, such as tables, views, and stored procedures.
  18. How do you secure a SQL Server database?
    • Answer: Securing a database involves implementing authentication and authorization, encrypting sensitive data, applying security patches, and following best practices for backup and recovery.
  19. What are the benefits of using stored procedures over dynamic SQL?
    • Answer: Stored procedures offer performance benefits through precompilation, security by encapsulating logic, reusability, and maintainability. They also help prevent SQL injection.
  20. Explain the concept of a primary key in SQL Server.Answer: A primary key uniquely identifies each record in a table. It enforces entity integrity by ensuring each value is unique and not null.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.