转载 : 原文地址 http://aspalliance.com/1255_Frequently_Asked_Questions_in_NET_20
Introduction | |||||||||||||||||||||||||||||||||
[
Back To Top ]
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 | |||||||||||||||||||||||||||||||||
[
Back To Top ]
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?
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
·
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.
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()?
| |||||||||||||||||||||||||||||||||
References | |||||||||||||||||||||||||||||||||
[
Back To Top ]
| |||||||||||||||||||||||||||||||||
Conclusion | |||||||||||||||||||||||||||||||||
[
Back To Top ]
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.
|