Những nguồn code mẫu (edit)
Những khóa học online miễn phí
7 luật để làm giao diện UI "tuyệt đỉnh"
10 code CSS đơn giản học trong 10 phút
.NET Interview questions and answers
1. Explain the difference between managed and unmanaged code.
Managed code is code created and compiled by the .NET compiler. Managed code does not depend on the architecture of the target machine because it is executed through the Common Language Runtime (CLR), and not by the operating system itself.
Unmanaged code is compiled directly to native machine code and depends completely on the architecture of the target machine. Unmanaged code is executed directly by the operating system.
2. What is the difference between an abstract class and an interface?
Abstract classes should always be used as base classes. Abstract classes provide virtual members which the inheriting entities should implement, as well as partial implementations for functionality. You cannot create objects from abstract classes.
Interfaces designate contracts or behaviors that implementing classes should have. Interfaces are able to declare properties, methods, and events. Developers should implement all declared members.
3. What are boxing and unboxing?
Boxing is simply the process of converting a value type to any interface type implemented by the current value type; the most common is the Value object. Boxing is used to store value types in the garbage-collected heap.
This means that, once a variable is boxed, it can hold a separate value in a separate memory location. When a value type is boxed, a new object must be allocated and constructed.
A simple example of Boxing looks like this:
Dim i As Integer
i = 123
Dim o As Object
o = i
The value of i gets copied into the variable o, because these two value types are compatible. Another example of Boxing is:
Dim i As Integer
i = 123
Dim L As Long
L = i
The variable i is compatible with the Long object, so it could be easily copied.
Unboxing simply extracts the value type from the object or the interface type. In contrast to boxing, the cast required for unboxing is not as expensive computationally. Unboxing is a conversion from the type Object to a value type or from an interface type to a value type that implements the interface.
An unboxing operation consists of the following:
A simple example of Unboxing is as follows:
Dim i As Integer
Dim o As Object
o = 123
i = DirectCast(o, i)
Here, the numeric value is initially of Type Object. Then, it gets converted to an Integer value.
For a better comparison between Boxing and Unboxing, please read "Boxing and Unboxing in VB.NET."
4. What is a delegate in .NET?
A delegate is simply a type that represents a reference to physical methods with the same parameter list and return type. Okay, what does that mean in simple terms? A delegate is basically a substitute for a method with the same return type and with the same signature. We make use of a delegate when we cannot access certain threads directly (as explained in this article), or when we need to ensure that managed and unmanaged code can be executed properly.
Delegates contain a reference to a method inside a delegate object. This object can, in turn, be passed to code that calls the referenced method, allowing the method to be invoked to be unknown at compile time.
"Using the MethodInvoker Delegate in Visual Basic" is a more detailed explanation of delegates.
5. Define Overriding.
Overriding is a .NET feature that allows a child class to provide a specific implementation of a method that is already provided by one of its parent classes. The implementation in the subclass replaces (overrides) the implementation in the parent class by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.
6. Explain LINQ in a nutshell.
LINQ (Language-Integrated Query) is a set of technologies based on the integration of query capabilities directly into a .NET language. Queries against data are expressed as basic strings without type checking at compile time or IntelliSense support. Query expressions are written in a declarative query syntax. By using query syntax, you can perform ordering, filtering, and grouping operations on data sources without a lot of code. LINQ uses a unified syntax irrespective of the type of data.
For more information regarding Language-Integrated Query, read through this "Doing Visual Basic LINQ."
7. Explain the difference between a stack and a queue.
When you go to a bank or a grocery store, you have to stand in a queue (line) for service. The first person in the queue is the first person helped. The last person in the queue is the last person helped. Agreed? Now, the Queue class works the same way. It is what is called a FIFO (First in, First out) list.
As "Queue Class" on MSDN article mentions: Queues are useful for storing messages in the order they were received for sequential processing. This class implements a queue as a circular array. Objects stored in a Queue are inserted at one end and removed from the other.
A Stack is the opposite of a Queue. Where a Queue is a FIFO list, a Stack represents a LIFO (Last in, First out) list. This analogy is the same as a stack of books. The first book you place on your desk, will remain at the bottom, whereas the last book that you have placed on the stack, will most likely be used/discarded first.
"Stack Class" on MSDN explains a Stack as: simple last-in-first-out (LIFO) non-generic collection of objects.
For more information regarding Queues and Stacks, please feel free to read through "Working with Queues and Stacks."
8. Discuss what garbage collection is and how it works.
The Garbage collector is an automatic memory manager that manages the allocation and release of memory for .NET applications. Every time a new object is created, the .NET Common Language Runtime (CLR) allocates memory for that particular object from the managed Heap. As long as free memory space is available in the managed Heap, the CLR continues to allocate space for new objects. When an application fills the Heap memory space, the garbage collector frees up some memory.
The Garbage Collector checks for objects in the managed Heap that are no longer being used by the application and performs the necessary operations to reclaim the memory. Garbage collection stops all running threads and it will find all objects in the Heap that are no longer being accessed by the main program and delete them. It then reorganizes all the objects left on the Heap to make space and adjust all the Pointers to these objects in the Heap.
9. What is the difference between user and custom controls?
A User Control is a user-specific control. Okay, so what does that mean? It means that sometimes there are circumstances where an ordinary Windows Control (those found in the Visual Studio Toolbox) does not suffice for the need at hand. There are times that a combination of Windows Controls fit one particular need; this is where a User Control can be extremely handy. There are a few types of User Controls; they are:
User Controls are much easier to create whereas custom controls require extra effort. User Controls are used when the layout is static and custom controls are used in dynamic layouts.
A User Control is not and can not be added to the Visual Studio Toolbox whereas a custom control can be. A copy of a User Control is required in every application that makes use of it. Custom controls are stored in the GAC (Global Assembly Cache), so only a single copy of the custom control can be used by all applications.
10. Give a very short explanation of Inheritance.
Inheritance means that a class can be based on another class, called a base class. In this case, the child class takes on the attributes of the parent class.
Interviews are tough. With this list of .NET interview questions, I hope I have helped by covering some of the popular .NET questions that get asked during an interview. Good luck!