Search This Blog

Thursday, February 11, 2010

Interview Questions DotNet

1. What are the difference between Value Types and Reference types?
Ans: Value types are those that are created on the stack. Reference types are created on the heap. Value types are destroyed when the block creating them is exited. Reference types are garbage collected. Reference types are like pointers.

2. What is boxing and unboxing in .NET?
Ans: Boxing is wrapping a value type into an object, so it can be stored on the heap. Unboxing is the converse – recovering a value type from a reference type on the heap. Boxing works always. Unboxing a reference type would work only if the type was originally a value type that was boxed.

3. What are three to five important differences that you would find between COM/DCOM and .NET?
Ans:
(I) COM/DCOM uses the registry to store all information related to the component. And .NET stores the information within the component itself
(II) All COM/DCOM components must be installed. .NET components can simply be xcopied (even though shared assemblies would need to be installed with gacutil.exe)
(III) COM/DCOM components implement the interface IUnknown (that has the methods: AddRef(), Release() and QueryInterface()) All .NET components inherit from the CTS type System.Object
(IV) COM/DCOM is not type-independent. For example, all COM server methods in VB must accept or return variants. In .NET, since all languages share the same type library (CTS – Common Type System) - this overhead is removed.
(V) DCOM uses a proprietary mechanism to discover remote objects, marshall the parameters and return back values. .NET uses open standards like XML to do remoting.
(VI) COM/DCOM depends on reference counts to know if they are needed. In .NET, the garbage collector takes care of keeping object lifetimes and collecting them when no longer needed.

4. What is non-CLS compliant code?
Ans: Non CLS compliant code is code where the .NET cross-language standards are broken. For example: Having two C# methods that accept the same parameters but differ in case. This would be unusable from the VB.NET world.

5. What does Shared Assembly mean? Can you make any assembly a shared one?
Ans: Shared Assemblies are those that are installed in a special folder within the Windows installation (called Global Assembly Cache). They can be used by any .NET application that needs to be a client to the assembly's methods. To make an assembly into a shared one, you need to generate a strong name. For this you have SN.EXE that generates public and private keys that can be used to version and strongly name the assembly in the GAC. Unless this is done, any and every assembly cannot become shared.
6. Where is the metadata related to an assembly stored?
Ans: In a special area of the assembly header, called its manifest. This manifest contains file ownership details, culture, version numbers, types referenced, types exported and other media.

7. Can each file of an assembly have its own manifest?
Ans: No. Only one file in an assembly can have its manifest.

8. What are three to five differences you would state, between ASP and ASP.NET ?
Ans:
. In ASP all the page contents are in the same file (or in included files). In ASP.NET, you can split the page's content and code into separate files (the code-behind file)
2. ASP files end with .asp. ASP.NET files end with .aspx (this is dumb )
3. With ASP you had just two main languages to write code – VBScript and JScript. With ASP.NET you can write code in any language that has a .NET compiler installed on the IIS server
4. All ASP pages are interpreted. ASP.NET uses compilation of the code-behind and runs the binaries everytime the page is requested.
5. ASP.NET adds a lot of functionality to IIS – like server controls, user controls, improved session management, event driven programming etc.
6. ASP pages usually post their forms to other asp pages. ASP.NET pages post the forms back to the same page (by calling server methods)

9. What are delegates in .NET? Mention 2 places where they are majorly used
Ans: Delegates are objects representing function pointers. Whenever a delegate is created, it is given the name of a function of the type it is defined with (like void return, accepting an int). Invoking the delegate calls the method it was created with (sort of a callback mechanism). Two places where delegates are employed: Events and Threads.

10. What are multicast delegates?
Ans: Multicast delegates are delegates that can refer to multiple methods. They must return void. Whenever we create a delegate with void, .NET internally treats it as a multicast delegate. We can use the overloaded + operator to add void methods with the same signature to a multicast delegate. When this delegate is called, all the methods are called (not in sequence – do not trust sequence).

11. What is meant by ViewState in ASP.NET?
Ans: ViewState is a hidden form member created with each control in ASP.NET. Like, when we populate a dropdown list on a page – its members are stored with the viewstate. They help in persisting form content state and can be used in a scenario where we have multiple web servers (as in a server farm).
12. What are static constructors in C#?
Ans: Static constructors are constructors in a class, defined with the word static. They must not accept any parameter and must return nothing. They are called once - whenever the class is loaded by the CLR. Every class can have 0 or 1 static constructors.

13. Are you aware of a keyword called fixed in C#? What is it used for?
Ans: The fixed keyword is used with references defined in a class. Whenever the word fixed is encountered, the .NET runtime/CLR flags this particular object on the heap.So that the garbage collector will not move it when it compacts the heap. Using fixed allows you to perform pointer arithmetic on objects (unsafe code)

14. What is the meaning of the following keywords:
a. Internal
Ans: Internal flags a member as being accessible only within the current assembly
b. Override
Ans: override allows a derived class to create a method that specializes a base class virtual method.
c. Sealed
Sealed classes are those that cannot be inherited from. You can make objects from a sealed class, but you cannot subclass it.

15. What are hidden methods in C#/.NET
Ans: hidden methods in C# use the new keyword. They are methods in a derived class that have the same signature as a base class virtual method, but are not related in inheritance to it. In effect, the derived class hides the base class method.

16. Can you have a catch block with no parameters (no catch (Exception e) ?
Ans: Yes. When you define a catch block with no parameters, you are defining a block that will handle exceptional information from the non .NET world. This would take care of problems arising in method calls on COM components that don’t raise the System.Exception derived object.

17. What is stackalloc in C#?
Ans: stackalloc is used for creating C/C++ style stack arrays. When you desire a contiguous block of memory where you could perform pointer arithmetic with a set of data, you use stackalloc. This is unsafe/unmanaged code. By default, all .NET arrays are objects created on the heap – even with integer arrays (Recall, you have a length property for all arrays!) You have no length property for stack allocated arrays

18. How is threading done in .NET?
Ans: The System.Threading namespace defines a class called Thread. This thread is created with a ThreadStart delegate class object. This ThreadStart object must refer to a method that accepts and returns void. When the start method is called on the thread, it runs the delegate method parallel with the current thread of execution.
19. What is meant by strongly typed assemblies?
Ans: Strongly typed assemblies can be placed in the GAC. They are created with a strong name (public/private key, generated with sn.exe)

20. What is the mechanism used to peep inside an object and know about its methods, public members etc?
Ans: Reflection. It is possible as all types inherit from System.Object, that contains a method GetType that returns a Type structure, describing the object's type.

21. Can session information be shared between ASP and ASP.NET?
Ans: No. They are maintained differently and cannot be shared. Session info written by an ASP.NET page cannot be viewed in an ASP page linked to the former.

22. Can you have two files in the same assembly, created with different programming languages?
Ans: Yes. .NET allows this.

23. Can you have a page where the code behind uses two different .NET languages?
Ans: No. Every page or class in .NET must be created in the same language.

24. What is the concept of generations in objects, as related to garbage collection?
Ans: Every object has a generation counter that is set and used by the garbage collector. It is incremented every time the object skips the garbage collection mechanism as its reference is present with some place else on the heap. The GC compacts the heap and places all objects with the same generation count together.

25. What is meant by DNA programming, in the Windows world?
DNA is short for Distributed interNet Architecture. It envisages an n-tier design where the client has UI functionality, the middle tiers have business logic and process routing architecture and the back-end has the database logic. DNA architecture allows the same business tiers and back-ends to be used by multiple clients (web, application-based or device)

26. What are the means to implement security in ASP.NET?
Ans:
1. Integrated Windows Authentication: Where the user's information and roles are defined in the windows installation where the IIS instance is active
2. Config file-based: The web.config file for the website has XML tags to indicate which users must be allowed and those that must be denied access.
You can make the root web folder publicly accessible, while restricting access to subfolders or selected files
3. Web-Service based: Microsoft runs a Passport web service that has a single door entry to authenticate users. Web applications could utilize this service to identify and permit users to access the system.

27. What is the class DataSet – in the ADO.NET world.
Ans: DataSet is an in-memory image of a database. It contains a set of tables and relations between them, that can be used by applications.

28. Is this possible? I use a Connection object to retrieve a SqlDataReader. I iterate through the records in the DataReader, using
while (sqlDataReaderObject.Read())
Inside the while block, I connect to some webservice to retrieve a value corresponding to a particular column in the record. Can I update another table in the same database, using the above connection – or would I have to create another connection object for the update thing?
Ans: No. This is not possible, as the Connection is locked by the SqlDataReader object, as long as it is being read from. You must create a new instance of the connection object, with the same connection string

29. Can I write an ASP.NET page using Managed C++?
Ans: Yes. But the C++ language must be enabled in the IIS' configuration files and the compiler must be available. By default, only two languages are supported – C# and VB.NET. To enable Managed C++, the compiler must be available. Else, the answer is no.

30. What is the Monitor class in the threading world?
Ans: Monitor is used to synchronize access to a block of code between threads. When a certain operation is to be performed by only one thread at a time, it must obtain the monitor to that object. Once it has acquired the monitor, all other threads to that method must wait till the monitor is exited.

No comments:

Post a Comment