Frequently Asked Questions in .NET 2.0
 
Published: 14 May 2007
Abstract
This article contains some of the frequently asked questions and answers in .NET 2.0 which should help all the Job seekers in .NET technology in preparation for interviews.
by Uday Denduluri
Feedback
Average Rating: 
Views (Total / Last 10 Days): 46919/ 77

Introduction

The questions and answers discussed in this article are the common questions programmers encounter in interviews. Most of the questions are basic questions of .NET and some of them are from ASP.NET 2.0.

Frequently Asked Questions

What is the difference between int and Int32?

Int32 is a class of namespace System. Keyword "int" is the alias of the class. So there is no real difference.

What does mutable and immutable means?

Immutable objects (read-only) are objects whose value cannot be modified once it has been created. Methods that appear to modify an immutable object actually return a new object that contains the modification (the previous object remains in memory until garbage collected).

Mutable Objects are objects whose value can be modified.

What is the difference between String class and StringBuilder class? Which one is better?

String Class is immutable and StringBuilder class is mutable. If the object has many operations involved then StringBuilder class is a better option.

What is CLR? Who loads the CLR into a process?

Common Language Runtime (CLR) is the commercial implementation of the specification Common Language Infrastructure (CLI). The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment. The CLR is the platform on which the complete .NET Framework has been developed.

Hosts will load the CLR into the process. For further information regarding this please refer to the article “Understanding Application Domains and CLR hosts.”

What is an Application Domain?

Application domains help in providing isolation, unloading, and security boundaries for executing managed code. These Application Domains are very similar to the operating system concept Process. The isolation of applications is achieved using Application Domains. This will help them to see that they do not affect each other.

For further information on Application Domains please refer the article “Understanding Application Domains and CLR hosts”

What are delegates?

A delegate in C# is similar to a function pointer in C or C++. Using a delegate allows the programmer to encapsulate a reference to a method inside a delegate object. The delegate object can then be passed to code which can call the referenced method, without having to know at compile time which method will be invoked. Unlike function pointers in C or C++, delegates are object-oriented, type-safe, and secure.

For further information on delegate please refer the article working with Delegates in C#

What is difference between delegates and Events?

A delegate is a reference to a method. A delegate is raw in its nature, but an event is hooked up with a control; it acts based on the behavior of the control. An event is a delegate, but a delegate is not an event. Event = Delegate + Event handling logic.

What is a partial class?

A Partial class is a class that can be split into two or more classes. This means that a class can be physically separated into other parts of the class within the same namespace. All the parts must use the partial keyword. All the other classes should also have the same access modifier. At the compile time, all the partial classes will be treated as a single class. Let us list some advantages of having partial classes.

·         Allows a clean separation of business logic layer and the user interface.

·         The UI code can be hidden from the developer.

·         Makes the debugging easier.

What is a Sealed Class? Where is it used?

A sealed class is a class for which there will be no derived class. The keyword sealed ensures no overriding of members.

In general all the API and framework classes are made to be sealed classes.

What are Generics?

Generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types they store or use. Using Generics, the type safety check burden will be on the compiler rather than developer. Hence, the Developer needs to write the code explicitly for checking type safety.

Listing 1

public class Generic<T> 
{
  public T Field;
}
Generic<string> g = new Generic<string>();
g.Field = "Some Value";

Listing 1 shows a simple example of Generics. The generic class defined has a field of the type T. The type T is initialized to be string.

What is the class name for accessing the Configuration in .NET 2.0?

The class name used for accessing configuration in .NET 2.0 is ConfigurationManager. The ConfigurationManager class is a static class which has all the methods for accessing application configuration file. For web applications we have WebConfigurationManager class. The WebConfigurationManager allows us to access machine and application information.

What is an Exception? What is the Base class for all the exception classes?

Exception is an unusual error condition that occurs during the execution of a program or an application. Whenever an exception occurs, the .NET runtime throws an object of type "Exception." All the Exceptions thrown by .NET runtime have their base class as Exception. For more information of handling exceptions please refer the article Exception Handling in .NET 2.0.

What is an Assembly?

An assembly is a basic building block for any application in the .NET Framework. It is a fundamental unit of deployment, version control, reuse, activation scoping, and security permissions. An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality. An assembly provides the Common Language Runtime (CLR) with the information it needs to be aware of type implementations. During runtime, a type does not exist outside the context of an assembly.

The contents of an assembly are the following.

·         CIL – Common Intermediate Language (formerly MSIL - Microsoft Intermediate Language)

·         Assembly Manifest – The Assembly Manifest has the information like Name, Version number, Culture, Strong Name information, etc.

·         Type Metadata

·         Resources

What is a Satellite Assembly?

Satellite Assembly is a .NET Framework assembly containing resources specific to a given language. Using a satellite assembly, we can place resources of different languages in different assemblies and the correct assembly is loaded into memory only if the user elects to view the application in that language.

How does CLR differentiate an Assembly from a Satellite Assembly?

Please refer to the article “Creating an Assembly Programmatically.”

What is a .NET module? How is a .NET module different from an Assembly?

A .NET module is a portable executable file of type.dll or .exe consisting of one or more classes. This is similar to a .NET assembly which consists of classes, namespaces, etc.

A .NET module can not be deployed alone. It has to be linked into an assembly. This can be done by using compiler’s /add module switch (if the compiler supports it), al.exe, or in .NET Framework 2.0, link.exe.

Can we programmatically write an Assembly?

Yes, we can programmatically write any assembly. Please refer to the article Creating an Assembly Programmatically for further details.

What is CodeDOM in .NET used for?

CodeDOM is an API that helps in creating and compiling a programming structure at Runtime. Creating a programming structure involves creation of Namespace, Type – Class, Interface and even methods at the Runtime.  The implementation of CodeDOM can be divided in the two ways shown below. The namespace for the CodeDOM is System.CodeDOM.

·         Compiling or Building the Programs at the Runtime

·         Using CodeDOM for generating a Program structure

For further information on CodeDOM please refer to the article Using CodeDOM in .NET 2.0.

What is GAC?

The Global Assembly Cache (GAC) stores assemblies specifically designated to be shared by several applications on the computer. Assemblies deployed in the global assembly cache must have a strong name. When an assembly is added to the global assembly cache, integrity checks are performed on all files that make up the assembly. GAC physically creates directories for each version of the assembly. The Global Assembly Cache (GAC), when viewed using Explorer, has its view rendered in a special manner by the OS shell. When an Assembly is added to GAC these are the attributes that it takes.

·         Assembly Name – Name of the Assembly

·         Version – Version [Major-Minor-Revision-Build]

·         Culture – Culture will be null for normal Assembly

·         Public Key Token - This is a 64-bit hash of the public key which makes the assembly name unique.

·         Processor Architecture – Either MSIL or x86

Life cycle of ASP.NET 2.0 Page

Life cycle of the page is defined as the list of events that get fired from the Page initialization to page rendering. The list of events is illustrated along with the descriptions.

Name of the Event

When does the event fire

PreInit

 

Occurs at the beginning of page initialization.

Init

Occurs when the server control is initialized, which is the first step in its lifecycle.

InitComplete 

Occurs when page initialization is complete.

PreLoad

Occurs before the page Load event.

Load

Occurs when the server control is loaded into the Page object.

PreRender

Occurs after the Control object is loaded, but prior to rendering.

PreRenderComplete

Occurs before the page content is rendered.

SaveStateComplete

Occurs after the page has completed saving all view state and control state information for the page and controls on the page.

LoadComplete

Occurs at the end of the load stage of the page's life cycle.

Unload

Occurs when the server control is unloaded from memory.

 

What is the Pre-Compilation feature of ASP.NET 2.0? How does the new folder structure help for the same?

By default, ASP.NET Web pages and code files are compiled dynamically when users first request a resource such as a page from the Web site. After pages and code files have been compiled the first time, the compiled resources are cached, so that subsequent requests to the same page are extremely efficient. This was in previous versions of ASP.NET, but in ASP.NET 2.0 we have a feature called as pre-compilation. With this, ASP.NET can also pre-compile an entire site before it is made available to users. We have some pre-defined folder structures for enabling this feature of pre-compilation. Let us list down some of the folders with a brief description of what they are meant for.

·         App_Code – meant for storing classes

·         App_Themes – meant for storing CSS files, Images, etc.

·         App_Data –meant for storing XML files, Text Files, etc.

·         App_GlobalResources – meant for storing all the resources at global level E.g. resx files, etc

·         App_LocalResources – meant for storing all the resources at local/Page level

What is Authentication in ASP.NET?

Authentication is the process of identifying a user with identification credentials like User name and Password with some authority. Generally after authentication the system gets to know who the user is. ASP.Net has some authentication providers. Let us discuss some of them.

Windows Authentication Provider - Windows authentication in conjunction with Microsoft Internet Information Services (IIS) authentication to secure ASP.NET applications

Forms Authentication Provider – An application-specific login form and performs authentication using user code.

Passport Authentication provider – Centralized authentication service provided by Microsoft offers a single login and core profile service for member sites.

What is Authorization in ASP.NET?

Authorization determines whether an identity/user should be granted access to a specific resource. Authorization requires that the authentication is already done. There are 2 ways to authorize access to a given resource:

·         File authorization - File authorization is performed by the FileAuthorizationModule. It checks the access control list (ACL) of the .aspx or .asmx handler file to determine whether a user should have access to the file.

·         URL authorization - URL authorization is performed by the UrlAuthorizationModule, which maps users and roles to URLs in ASP.NET applications.

Listing 2

<authorization>
  <[allow|deny] users roles verbs />
</authorization>

What is the difference between Response.Redirect() and Server.Transfer()?

Redirect Method

Transfer Method

Client knows about the redirection of the URL.

 

Client does not know anything about the transfer. It appears to be the same old URL for the client.

ASP.net can force reauthorization by using the Redirect method instead of the Transfer method.

ASP.NET does not verify that the current user is authorized to view the resource delivered by the Transfer method. You need to have a Custom logic for the same.

Response.Redirect is little bit slower, but it retains the new URL.

Server.Transfer is faster as it reduces 1 less trip to the client.

Cannot use HTTPContext.Items.

HTTPContext.Items are accessible.

References

Conclusion

The questions discussed are more like basic questions. They help the programmer to clear the initial round of interviews, but going deeper into the interviews he or she may get questions based on Architectural issues, project related topics, etc. So make sure you prepare yourself.



User Comments

Title: cookie   
Name: Srikanth N S
Date: 8/26/2010 1:50:02 AM
Comment:
how do v create cookies?
Title: gud article   
Name: sanjay gera
Date: 4/13/2010 6:39:28 AM
Comment:
thanks for article
Title: very nice article   
Name: Ramarao.Gogineni
Date: 6/29/2009 8:42:03 AM
Comment:
iam very much thankful to the author keep it up.
Title: This is our opportunity.Thnku   
Name: Raghu Hyd
Date: 4/3/2009 10:26:00 AM
Comment:
We r all glad to u.Give few more FAQs
Title: thanks for article given   
Name: Beeshow
Date: 11/3/2008 5:10:31 AM
Comment:
great job ,,buddy
Title: good article   
Name: Sujith Mysore
Date: 9/10/2008 2:37:26 AM
Comment:
Great Article...Keep up the good work..cheers
Title: Questions on ASP.NET 2.0   
Name: CRM Developer
Date: 6/10/2008 3:54:44 AM
Comment:
nice Article, Thanks
Title: Great Job, Please post more Faqs, we are very thankful to u.   
Name: D.Ravikiran
Date: 4/24/2008 1:32:50 AM
Comment:
Great Job, Please post more Faqs, we are very thankful to this site and authors.

We appreciate your work.
Title: great job   
Name: amit anand
Date: 8/23/2007 8:26:49 AM
Comment:
seriously very useful....thanx so much
Title: Nice Article   
Name: Srinivasu Pemma
Date: 8/12/2007 5:29:42 AM
Comment:
HI all,

I found a good article over the net today.
I am very much thankful to the author
Title: FAQ's   
Name: Nitin Sharma (.Net Technologies)
Date: 6/18/2007 5:59:56 AM
Comment:
Really Good......!!!!Thw way of explaining is very very good ...If i have to search something in google,i enter aspalliance along with the keywords..Great job aspalliance and all your partners.....

Keep it Up.....!!!!!
Title: good   
Name: jansi
Date: 6/8/2007 1:33:39 AM
Comment:
This is very much useful.
Title: Very Nice Work   
Name: Nirav Valera
Date: 5/30/2007 7:00:15 AM
Comment:
This is the really good job.
Title: good work   
Name: kapil sharma
Date: 5/24/2007 3:15:39 AM
Comment:
this is the good job work but there is not enough some more question add.
Title: Developer   
Name: Uday
Date: 5/14/2007 2:39:43 PM
Comment:
Thanks Kelvin and Paul
Title: Partial Classes   
Name: Paul
Date: 5/14/2007 11:08:25 AM
Comment:
Nice article, but I was shocked when I read the part on partial classes.

"A Partial class is a class that can be split into two or more classes."
A partial class is a class whose definition can be split into two or more files.

The main purpose of partial classes are to be able to separate generated files from custom files and not have to have a "...Base" class.

http://msdn.microsoft.com/msdnmag/issues/06/00/C20/default.aspx#S4

Quote from above link:
"Partial types are a very handy feature. Sometimes it is necessary to modify a machine-generated file, such as a Web service client-side wrapper class. However, changes made to the file will be lost if you regenerate the wrapper class. Using a partial class, you can factor those changes into a separate file."
Title: Developer   
Name: Kelvin
Date: 5/14/2007 10:05:35 AM
Comment:
System.Int32 is a structure, not a class.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2014 ASPAlliance.com  |  Page Processed at 10/21/2014 12:45:51 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search