Pages

Monday, July 4, 2011

.NET and C# interview questions:Show how do we view an assembly in .NET?


When coming to understand the internals, nothing can beat ILDASM. ILDASM converts the whole ‘exe’ or ‘dll’ in to IL code. To run ILDASM you have to go to ‘C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin’. Note that we had v1.1 you have to probably change it depending on the type of framework version you have.
If you run IDASM.EXE from the path you will be popped with the IDASM exe
program as shown in figure. Click on file and browse to the respective
directory for the DLL whose assembly you want to view. After you select the
DLL you will be popped with a tree view details of the DLL as shown in
figure ILDASM. On double clicking on manifest, you will be able to view
details of assembly, internal IL code etc as shown in the figure.

Note: - The version number are in the manifest itself which is defined with
the DLL or EXE thus making deployment much easier as compared to COM where
the information was stored in registry. Note the version information in Figure
Manifest view.
You can expand the tree for detail information regarding the DLL like methods, properties, functions etc.


And once you open the Manifest you will be able to see the inner details as shown in the following picture: -


Following is the video which shows that how the questions are asked C#
and .NET interviews.

C# and .NET interview questions: Explain in brief an interface?

Interface is a contract that defines the signature of the functionality. So if a class is implementing a interface it says to the outer world, that it provides specific behavior. Example if a class is implementing ‘Idisposable’ interface that means it has a functionality to release unmanaged resources. Now external objects using this class know that it has contract by which it can dispose unused unmanaged objects.
  • Single Class can implement multiple interfaces.
  • If a class implements a interface then it has to provide
    implementation to all its methods.

Following code shows that one has the interface definition and other
class implements the interface. Below is the source code “IInterface” is the
interface and “ClsDosomething” implements the “IInterface”. This sample just
displays a simple message box.

Public Interface IInterFace
Sub Do Something ()
End Interface

Public Class ClsDoSomething
Implements IInterFace
Public Sub DoSomething () Implements WindowsInterFace.IInterFace.DoSomething
MsgBox (“Interface implemented”)
End Sub
End Class

After implementing the above code you will get the following output as shown:


Following you can see a simple video on boxing and unboxing:


.NET and ASP.NET interview questions: Define MVC, MVP and MVVM pattern?

MVC, MVP and MVVM are design patterns which come under the presentation pattern category and they help to remove any kind of cluttered code in UI like manipulation of user interfaces and maintaining state. Thus keeping your UI code cleaner and better to maintain.
MVC(Model view controller) pattern divides the architecture into 3 parts model, view and controller. The first request comes to the controller and the controller then decides which view to be displayed and ties up the model with the view accordingly.

MVP (Model view presenter) has the same goals as MVC i.e. separating the UI from the model. It does the same by using a presenter class. The UI talks via an interface to the presenter class and the presenter class talks with the model.

MVVM is an architectural pattern with the focus of removing UI cluttered code. It does the same by using an extra class called as view model. MVVM is mostly suitable for Silverlight and WPF projects because of the rich bindings provided by the technologies.