Dot Net Interview Questions – Set 03

How to retrieve user name in case of Window Authentication?

System.Environment.UserName

What is the difference between Hash table and Array list?What is the difference between Hash table and Array list?

Hash table stores data in the form of value pair and name while Array list stores only values.

You need to pass name to access value from the Hash table while in Array, you need to pass index number to access value.

In Array, you can store only similar type of data type while in Hash table you can store different type of data types. ex. int, string etc.

What is the difference between int and int32?

There is no difference between int and int32. System. Int is an alias name for System.Int32 which is a .Net Class.

Explain the difference between the while and for loop. Provide a .NET syntax for both loops.

Both loops are used when a unit of code needs to execute repeatedly. The difference is that the for loop is used when you know how many times you need to iterate through the code. On the other hand, the while loop is used when you need to repeat something until a given statement is true.

The syntax of the while loop in C# is:

while (condition [is true])
{
// statements
}
The syntax of the while loop in VB.NET is:

While condition [is True]
‘ statements
End While
The syntax of the for loop in C# is:

for (initializer; condition; iterator)
{
// statements
}
The syntax of the for loop in VB.NET is:

For counter [ As datatype ] = start To end [ Step step ]
‘ statements
Next [ counter ]

Explain what inheritance is, and why it’s important.

Inheritance is one of the most important concepts in object-oriented programming, together with encapsulation and polymorphism. Inheritance allows developers to create new classes that reuse, extend, and modify the behavior defined in other classes. This enables code reuse and speeds up development. With inheritance, developers can write and debug one class only once, and then reuse that same code as the basis for the new classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. By default, all classes in .NET are inheritable.

What is the meaning of Immutable?

Immutable means once you create a thing, you cannot modify it.

For example: If you want give new value to old value then it will discard the old value and create new instance in memory to hold the new value.

What is the difference between namespace and assembly?

An assembly is a physical grouping of logical units while namespace groups classes. A namespace can span multiple assemblies.

What is the difference between Stack and Heap?

The stack is used for static memory allocation and access to this memory is fast and simple to keep track of. Heap is used for dynamic memory allocation and memory allocation to variables happens at run time. Accessing the heap memory is complex and slower compared to stack.

Explain the differences between an Interface and an Abstract Class in .NET.

An interface merely declares a contract or a behavior that implementing classes should have. It may declare only properties, methods, and events with no access modifiers. All the declared members must be implemented.

An abstract class provides a partial implementation for a functionality and some abstract/virtual members that must be implemented by the inheriting entities. It can declare fields too.

Neither interfaces nor abstract classes can be instantiated.

Explain in basic terms how to execute managed code.

Executing code is an essential function of any developer, but knowledge of executing managed code is specific to the .NET Framework. Your answer should explain how to execute code that runs inside the common language runtime environment the framework provides.

Additionally, whenever an interviewer asks you to explain something in “basic terms,” it’s important to pay attention to the language you use to make it as clear as possible. These types of questions are often asked when the position requires the candidate to be both very technical and also a good communicator who can explain their work to a broad audience. In some organizations, a lead developer may be responsible for reporting progress on an application to stakeholders. During these exchanges, they should be able to break down their work without using technical jargon or overly complicated language.

Example: “First, I would write the code. Then I would compile the code with a resource called a compiler. Using the compiler, I would convert the managed code into an intermediate language. The intermediate language will be targeted by the Common Language Runtime within .NET Framework and converted to native code that can then be executed inside the framework.

In my previous role as a developer, I was tasked with speeding up application delivery times. Using .NET and this process for executing managed code, I was able to reduce delivery timelines by 5% overall.”