Corporate Training
Request Demo
Click me
Menu
Let's Talk
Request Demo

.Net Interview Questions and Answers

by Venkatesan M, on May 23, 2017 6:07:40 PM

.Net Interview Questions and Answers

Q1. What is .NET Framework?

Ans: .NET Framework is a software development platform developed by Microsoft. It provides a runtime environment to create, deploy, and run applications, including libraries, languages, and tools for different programming languages.

Q2. What is the Common Language Runtime (CLR)?

Ans: CLR is the heart of the .NET Framework. It provides various services such as memory management, security, type safety, and exception handling. It also compiles and executes managed code into native code.

Q3. What are Managed and Unmanaged Code?

Ans: Managed code is written in languages like C#, VB.NET, etc., that run within the .NET Framework. Unmanaged code is written in languages like C++ and directly interacts with hardware and memory, without CLR's control.

Q4. Explain CTS and CLS.

Ans: 

  • Common Type System (CTS) ensures that different .NET languages can interoperate seamlessly by defining data types at a common level.
  • Common Language Specification (CLS) is a set of rules and guidelines to ensure language interoperability and code reusability within the .NET Framework.

Q5. What is the difference between Value Types and Reference Types?

Ans: Value types store the actual value, while reference types store a reference to the value's memory location. Value types include primitive types like int, float, bool, etc., while reference types include classes, interfaces, delegates, etc.

Q6. What are Boxing and Unboxing?

Ans: Boxing is the process of converting a value type to an object type (e.g., int to object). Unboxing is the opposite operation, converting the object back to a value type.

Q7. Explain JIT Compilation.

Ans: Just-In-Time (JIT) compilation is the process where CLR converts Intermediate Language (IL) code to native machine code right before execution. This improves performance by allowing optimizations based on the actual environment.

Q8. What is Garbage Collection?

Ans: Garbage Collection (GC) is the process of automatically managing memory by identifying and reclaiming memory occupied by objects that are no longer referenced by the program.

Q9. Describe the differences between Finalize and Dispose.

Ans: Finalize is a method called by the GC before an object is removed from memory. Dispose is a method used to release unmanaged resources early, implementing the IDisposable interface, and can be called explicitly by the programmer.

Q10. What are ASP.NET Web Forms and ASP.NET MVC?

Ans: ASP.NET Web Forms is a framework for building web applications using a page-based model with controls. ASP.NET MVC is a pattern for designing web applications, separating concerns into Model, View, and Controller components.

Q11. Explain the MVC pattern.

Ans: MVC stands for Model-View-Controller. It's a design pattern where the application is divided into three components: Model (data and logic), View (user interface), and Controller (handles user input and coordinates between Model and View).

Q12. What is the difference between ViewData and ViewBag?

Ans: Both ViewData and ViewBag are used to pass data from Controller to View in ASP.NET MVC. ViewData uses a dictionary, while ViewBag uses dynamic properties. ViewBag provides a more concise syntax but lacks compile-time safety

Q13. What are the different types of ASP.NET State Management?

Ans: ASP.NET provides various mechanisms to manage state:

ViewState: Stores page-specific data.
Session State: Stores user-specific data across multiple requests.
Application State: Stores data shared among all users.
Cookies: Stores small amounts of data on the client's machine.
Query String: Stores data in the URL.


Q14. Explain the concept of Routing in ASP.NET MVC.

Ans: Routing maps URLs to controller actions. It allows for creating user-friendly URLs that map directly to specific controller methods, enhancing SEO and usability.

Q15. What is Entity Framework (EF)?

Ans: Entity Framework is an Object-Relational Mapping (ORM) framework that simplifies database interaction by allowing developers to work with databases using .NET objects. It automates the mapping between objects and database tables.

Q16. What is LINQ?

Ans: Language Integrated Query (LINQ) is a set of features that allow developers to perform queries on collections and databases directly from C# code. It provides a unified syntax for querying different data sources.

Q17. Explain the different types of Authentication in ASP.NET.

Ans: ASP.NET supports various authentication methods:

  • Windows Authentication: Uses Windows user accounts.
  • Forms Authentication: Uses custom login forms and cookies.
  • Identity Authentication: Uses ASP.NET Identity for more flexible user management.
  • OAuth and OpenID: For external authentication providers.

Q18. What is ADO.NET?

Ans: ADO.NET is a data access technology that allows developers to connect to databases, retrieve and manipulate data using .NET objects. It includes classes like SqlConnection, SqlCommand, SqlDataAdapter, etc.

Q19. Describe the difference between Abstract Classes and Interfaces.

Ans:

  • Abstract Classes: Can have both concrete and abstract methods, can contain fields, and support single inheritance.
  • Interfaces: Can only have abstract methods, can't contain fields, and support multiple inheritance.

Q20. What is Reflection?

Ans: Reflection allows you to inspect and manipulate metadata, types, and objects at runtime. It enables dynamic loading of assemblies, creating instances of types, and invoking methods without knowing them at compile time.

Q21. Explain the purpose of the Global Assembly Cache (GAC).

Ans: The GAC is a central repository for storing shared .NET assemblies that need to be accessible across multiple applications. Assemblies in the GAC have a strong name, ensuring versioning and security.

Q22. What is Serialization?

Ans: Serialization is the process of converting objects into a format that can be stored or transmitted and then reconstructing them back into objects. .NET provides Binary, XML, and JSON serialization.

Q23. How does Exception Handling work in .NET?

Ans: Exception handling in .NET is managed using try-catch blocks. When an exception occurs, the runtime searches for an appropriate catch block to handle it. If none is found, the application terminates.

Q24. What are Delegates?

Ans: Delegates are type-safe function pointers that allow you to define and pass methods as arguments to other methods. They're commonly used for event handling and callbacks.

Q25. Explain Events in C#.

Ans: Events allow objects to notify other objects when something of interest happens. They are based on delegates and provide a way to implement the Observer pattern.

Q26. Describe the concept of Multithreading in .NET.

Ans: Multithreading allows an application to execute multiple threads concurrently, improving performance and responsiveness. .NET provides the Thread class and higher-level constructs like Tasks and async/await for asynchronous programming.

Q27. What is the use of the "using" statement in C#?

Ans: The "using" statement is used for automatic resource management, especially for objects that implement IDisposable. It ensures that the object's Dispose method is called, freeing up resources.

Q28. What is the purpose of the "as" operator in C#?

Ans: The "as" operator is used for safe type casting. If the conversion fails, it returns null instead of throwing an exception.

Q29. Explain the "is" operator in C#?

Ans: The "is" operator is used to check whether an object is of a specified type. It returns a boolean value indicating the result of the type check.

Q30. How does Late Binding differ from Early Binding?

Ans:

  • Early Binding: Occurs at compile-time, providing better performance and compile-time type checking. Achieved using static typing.
  • Late Binding: Occurs at runtime, allowing more dynamic behavior and flexibility. Achieved using mechanisms like reflection and dynamic types.

Q31. What is Code Access Security (CAS)?

Ans: Code Access Security is a security model in .NET that controls the permissions of code based on the source of the code, the identity of the user, and other factors. It ensures that code can only access resources it has permission to access.

Q32. What is the difference between String and StringBuilder?

Ans:

String: Immutable, concatenation creates new instances, less efficient for frequent modifications.
StringBuilder: Mutable, designed for efficient string concatenation and modification.

Q33. What is the purpose of the "readonly" keyword in C#?

Ans: The "readonly" keyword is used to declare constants that are evaluated at runtime, but their values can't be modified after initialization.

Q34. Explain Inversion of Control (IoC) and Dependency Injection (DI).

Ans: IoC is a design principle where control over object creation and lifecycle is shifted from the application to a container. DI is a technique used to implement IoC, where a class's dependencies are injected through constructor parameters or properties.

Q35. What is the difference between Shallow Copy and Deep Copy?

Ans:

Shallow Copy: Copies references, not actual objects. Changes in the original reflect in the copy.
Deep Copy: Creates new instances of objects being copied. Changes in the original don't affect the copy.

Q36. What is the purpose of the "volatile" keyword in C#?

Ans: The "volatile" keyword is used to indicate that a field's value may change at any time, preventing the compiler from performing certain optimizations.

Q37. Explain the "yield" keyword in C#.

Ans: The "yield" keyword is used to create iterator methods that return a sequence of values. It simplifies the process of creating iterators by automatically generating state machine code.

Q38. What is the Dispose Pattern?

Ans: The Dispose Pattern is used to release unmanaged resources and perform cleanup operations when an object is no longer needed. It involves implementing the IDisposable interface and calling Dispose() explicitly.

Q39. What is the difference between "throw" and "throw ex" in C# exception handling?

Ans:

"throw": Rethrows the current exception while maintaining the original call stack.
"throw ex": Rethrows the current exception, but the original call stack is lost, making debugging more challenging.

Q40. Explain the concept of Asynchronous Programming in C#.

Ans: Asynchronous programming allows you to perform non-blocking operations, ensuring that the application remains responsive. This is achieved using the "async" and "await" keywords.

Q41. What is a Tuple in C#?

Ans: A Tuple is a lightweight data structure that allows you to store a sequence of heterogeneous elements. Tuples are commonly used when you need to return multiple values from a method.

Q42. What are Extension Methods in C#?

Ans: Extension methods allow you to add new methods to existing types without modifying their source code. They're particularly useful for adding utility methods to framework classes.

Q43. Explain the Null Conditional Operator (?.) in C#.

Ans: The Null Conditional Operator is used to safely access members of an object without causing a null reference exception. If the object is null, the expression evaluates to null.

Q44. What are Indexers in C#?

Ans: Indexers allow objects to be indexed just like arrays, enabling custom data access mechanisms for objects.

Q45. What is the purpose of the "params" keyword in C#?

Ans: The "params" keyword allows you to pass a variable number of parameters to a method, which are treated as an array within the method's body.

Q46. Describe the difference between a Value Type and a Reference Type in C#.

Ans:

Value Type: Holds the actual value and is stored on the stack. Examples include int, float, and struct.
Reference Type: Holds a reference to the value's memory location and is stored on the heap. Examples include classes, interfaces, and delegates.

Q47. What are Anonymous Types in C#?

Ans: Anonymous types allow you to create objects without explicitly defining a class. They are useful for ad-hoc data structures.

Persistent Cookie – Resides on a user’s machine for a period specified for its expiry, such as 10 days, one month, and never.

Q48. What is the file extension of web service?

Ans: Web services have file extension .asmx..

Q49. What is the difference between a Static Class and a Singleton Class?

Ans:

Static Class: Cannot be instantiated, contains only static members.
Singleton Class: Instantiated only once, typically via a static property or method, and maintains a single instance throughout the application.

Q50. Describe the "using" directive in C#.

Ans: The "using" directive is used to import namespaces so that you can use types from those namespaces without fully qualifying their names.

Q51. What are Attributes in C#?

Ans: Attributes provide metadata about program entities, such as classes, methods, and properties. They're used for adding information that can be retrieved at runtime using reflection.

Q52. What is Reflection.Emit in C#?

Ans: Reflection.Emit is a part of the Reflection namespace that allows you to generate and define new types, fields, methods, and other constructs at runtime.

Q53. Explain Partial Classes in C#.

Ans: Partial classes allow a single class to be defined across multiple source files. This is especially useful when a class is large and has parts that are generated or maintained automatically.

Q54. What are Extension Methods in C#?

Ans: Extension methods allow you to add new methods to existing types without modifying their source code. They're particularly useful for adding utility methods to framework classes.

Q55. What is Lazy Initialization in C#?

Ans: Lazy initialization is a design pattern that defers the creation of an object until the first time it's needed. It's useful for improving performance by only creating objects when they're actually required.

Q56. Explain the "params" keyword in C#.

Ans: The "params" keyword allows you to pass a variable number of arguments to a method by using an array-like syntax.

Q57. What is Object Pooling?

Ans: Object pooling is a technique used to manage and reuse objects to improve performance, especially for objects with high instantiation and disposal costs.

Q58. Explain the concept of Type Conversion in C#.

Ans: Type conversion involves changing the type of a value from one type to another. It can be implicit (automatic) or explicit (manual) using casting.

Q59. What is Dynamic Binding in C#?

Ans: Dynamic binding allows you to defer the resolution of method calls, property access, and other operations until runtime. This is achieved using the "dynamic" keyword.

Q60. What is the purpose of the "nameof" operator in C#?

Ans: The "nameof" operator returns the name of a variable, type, or member as a string. It's helpful for avoiding hard-coded strings when working with reflection.

Q61. Explain the concept of Finalization in C#.

Ans: Finalization refers to the process of cleaning up an object before it's destroyed by the garbage collector. It involves implementing a finalizer method using the destructor syntax.

Q62. What is the difference between Covariance and Contravariance in C#?

Ans:

Covariance: Allows you to use a more derived type for a delegate or interface method's return type.
Contravariance: Allows you to use a less derived type for a delegate or interface method's parameter type.

Q63. Describe the Volatile Keyword in C#.

Ans: The "volatile" keyword indicates to the compiler that a variable's value may change at any time by external means. This prevents certain optimizations that could lead to incorrect behavior.

Related Interview Questions...

ASP.Net Web API Essentials using C# Interview Questions

VB.NET Interview Questions and Answers

ASP.NET MVC Interview Questions and Answers

ASP.NET Interview Questions and Answers For Experienced

ASP.NET Interview Questions and Answers

.NET Apps Interview Questions

Topics:.Net Interview Question and AnswerInformation Technologies (IT)

Comments

Subscribe

Top Courses in Python

Top Courses in Python

We help you to choose the right Python career Path at myTectra. Here are the top courses in Python one can select. Learn More →

aathirai cut mango pickle

More...