Top 28 .NET Interview Questions and Answers for Senior .NET Developers

.Net, a widely used framework for developing Windows applications, encompasses languages such as C#, Cobol, Perl, and VB.Net etc. Are you looking for a job in this domain? Here is a list of expected .NET interview questions and answers that will help you get through your next interview. Let’s go for it:

1. What is the .Net framework and how does it work?

It is a virtual machine that executes a managed code. The code is compiled from C# or VB .NET and is executed by the CLR (Common Language Runtime).

Its working is as follows:

  • You create a program in C # or VB.Net and compile it. The code is then translated to CIL (Common Intermediate Language).
  • The program is assembled into bytecode to generate a CLI (Common Language Infrastructure) assembly file of.exe or .dll format.
  • When you run the program (or the DLL), it is executed by the .Net framework CLR (Common Language Runtime). Since the code isn’t directly run by the operating system, it is called “Managed Code”.
  • The .Net Framework CLR, through the JIT (Just-In-Time) Compiler, is responsible for compiling this code managed in intermediate language. The compiled code is then sent to the native machine language assembler for the CPU to execute it.

The CIL (Common Intermediate Language) is the language that understands the.Net Framework.

C # and VB .Net are languages that we understand as humans.

C # and VB .Net are translated to CIL.

2. What is Heap and what is Stack?

  • Both are memory locations, wherein Heap is global and Stack is local.
  • The Heap is application level while the Stack is thread-level.
  • The Stack has a defined first-in first-out stack structure, while the Heap does not have a defined data structure.
  • Its size is defined at the time of its creation. For Heap, the size is defined when starting the application and for Stack, when creating a thread.
  • Both can grow dynamically.
  • The Stack is faster than the Heap. A stack is in “cache” and doesn’t have to synchronize with other threads like the Heap.
  • The Stack stores values while the Heap stores objects.

3. What is Garbage Collector?

Garbage Collector is an automatic process of memory release. When memory goes low, it goes through the Heap and eliminates the objects no longer in use. It frees up memory, reorganizes remaining threads and adjusts pointers to these objects, both in Heap and Stack.

4. What is a delegate?

It is the definition of a method that encapsulates certain arguments and type of return. It allows passing a method as an argument of a function, as long as it matches its specific signature.

5. What is LINQ?

It is standardization to consult data and convert it into objects, regardless of the source. It is a query manager for databases, XML and enumerable collections using a single language.

6. How does LINQ work?

Internally build the correct query (in the case of databases) or generate the corresponding operations on the collections or parse the XML and returns the relevant data. It encapsulates all these behaviours and provides a single implementation, in this way, we can use the same queries, the same language, independently of the underlying data source.

7. What are the deferred execution and the immediate execution in LINQ?

A deferred execution encapsulates a query’s definition without executing it till the data is used at runtime. However, an immediate implementation calls the query at the same moment of its definition.

By default, the executions are deferred but we can do them immediately by calling “To List ()”. For example, in this way, a list of objects will be executed and returned to us when we define it.

8. What are an object and a class?

An object is an instance of a class, and a class is a template for creating objects. Class is the definition of an object, the description of its characteristics and operations, its properties and its methods. An object has an identity because its characteristics have values.

9. What are inheritance, polymorphism, and encapsulation?

Inheritance is the ability to reuse definitions from one class in another and to base one class on another.

Polymorphism helps declare the same method within a class with different argument or return types.

Encapsulation is to be able to expose only the methods, property and arguments necessary to use the operations of a class. However, the detailed implementation remains private, hidden to other objects.

10. What is the difference between an abstract class and an interface?

  • An abstract class can contain both public and private constructors, methods, and fields. On the contrary, the interface contains only methods and public properties.
  • You can only inherit from an abstract class, but implement many interfaces.
  • An interface defines behaviour, something that the class that implements it can do. Contrary, an abstract class defines what the class is and what it represents.
  • You can’t instantiate anyone.
  • An abstract class is useful when creating components, making a partial initial implementation and a specific definition. This leaves you free to implement other methods.

.net interview questions and answers

11. Difference between public and static modifiers.

To invoke a method, field, or static property, you don’t need to instantiate the class.

On the other hand, to invoke a public method, you need an instance of a class.

12. What is a sealed class?

It is a class that is not inheritable. A sealed class comes in use for a super specialized class, by design, and prevents modification by overwriting.

13. What is a “jagged array”?

It is an arrangement of arrangements.

14. What is serialization?

Serialization converts an object to a data stream. However, for this, you must implement ISerialize.

15. What is the difference between constants and read-only variables?

For constants, compilation contains declaration and initialization. Its value cannot change. For read-only variables the runtime execution contains the assignment of values.

16. Explain Mutex

Threads share a mutually exclusive resource manager, Mutex. It ensures that only one thread at a time makes use of one resource (one object) at a time. It is like a moderator that controls the microphone and gives the word to one person at a time. Thus, Mutex grants access to resources one thread at a time. For this, it puts the threads that want to access resources “on hold” until those are in use.

17. What is immutability, what is it for and how is it codified?

The ability of objects not to change their state, once created, helps improve the maintainability of the code. When a mutable object encapsulates its changes without being explicit in the code, following the flow becomes difficult. The level of difficulty increases in case of multi-threaded applications. To create immutable objects, pass the arguments for their creation in the constructor; make their properties read-only later.

18. What is the difference between Override and Overload in a method?

Override is to overwrite the method with same signature (parameters and return type) but different functionality. Overwriting requires a “virtual” declaration of the method.

On the other hand, overloading refers to coding several versions of the same method. Though “virtual” declaration for a method is not necessary to overload, it requires a different signature (parameters and/or return value).

19. What is the difference between struct and class?

A class is a definition of an object and is inheritable. A structure, on the other hand, defines a type of data and is non-inheritable.

20. What is the difference between ODBC and ADO?

Open Database Connectivity is a standard for managing database operations in applications. The standard uses the same methods for Oracle as for Mysql. For example, it declares the connection with particularity at the user or operating system level.

ADO is a set of .Net libraries for data management, including ODBC connections. For ADO, ODBC is a driver.

21. What is the difference between encrypting a password and applying a hashing?

It is quite difficult (almost impossible) to decrypt a hashing (MD5 or SHA1, for example). The process of password validation compares the password in plain text with a hash to the stored one.

Conversly, one can decrypt an encrypted password with access to the keys and the encryption algorithms (such as Triple-DES).

22. What is Reflection and what is it for?

It is the ability to read, instantiate, and invoke the properties & methods of an assembly’s classes. It is especially useful when we do not have the source code for classes, only their assembly.

23. What is a design pattern and what is it for? Give some examples

It is a reusable template to solve a common problem at the design level. It is not the code but best practices to codify a solution. Some examples are Singleton, Abstract Factory, Observer or Pub/Sub, Model View Controller, Model View Presenter, and Model-View View-Model.

24. Why do we use the “using” statement?

We use the “using” statement to make sure that we release the resources of the object in use. It always calls “Dispose of” when it finishes its block of code.

25. What is a variable of implicit type and what is its scope?

It is a variable that doesn’t require type declaration since the compiler automatically determines its type. Its scope is local, within a method. It only allows inferring the kind the first time it assigns a value to the second. However, if the type is different, it throws an error.

.net interview questions and answers

26. What is an anonymous method and how is it different from a lambda expression?

For an anonymous method, the declaration comes before its use and implementation through a delegate. Also, this method doesn’t require a name.

A lambda expression refers to an anonymous method in a single line, elegantly replacing the representative for this function.

27. What is the Native Image Generator?

It is a tool that compiles the .Net assemblies to machine code for a specific processor. In this way, it improves its performance since the JIT no longer intervenes.

28. Is the JIT an interpreter?

No, the JIT is not an interpreter. It is a compiler at runtime that improves performance compiling method by method only once. If the method is called a new account, the native code already compiled is used. However, an interpreter executes the same every block of code.

I hope this list of top 28 .NET interview questions and answers helps you in getting your next job.

 

Did you find these .NET interview questions and answers useful?  Feel free to share your feedback and concerns in the comment section below.

[yikes-mailchimp form=”1″]

2 Responses

Leave a Reply

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

Recommended for you
Connect With Us
Stay Connected
Subscribe to our newsletter today to receive updates on latest tech news, tutorials SEO tips many more.
Latest Articles