Tuesday, March 10, 2009
Interview Question On Dot Net
assembly, how to say that name in the code?
A: The primary steps to properly design custom attribute classes are as follows:
Applying the AttributeUsageAttribute ([AttributeUsage(AttributeTargets.All, Inherited =
false, AllowMultiple = true)])
Declaring the attribute. (class public class MyAttribute : System.Attribute { // . . . })
Declaring constructors (public MyAttribute(bool myvalue) { this.myvalue = myvalue; })
Declaring properties public bool MyProperty{get {return this.myvalue;}set {this.myvalue
= value;}} The following example demonstrates the basic way of using reflection to get
access to custom attributes. class MainClass {public static void
Main(){System.Reflection.MemberInfo info = typeof(MyClass);object[] attributes =
info.GetCustomAttributes();for (int i = 0; i <>
17.What is the managed and unmanaged code in .net?
The .NET Framework provides a run-time environment called the Common Language
Runtime, which manages the execution of code and provides services that make the
development process easier. Compilers and tools expose the runtime's functionality and
enable you to write code that benefits from this managed execution environment. Code
that you develop with a language compiler that targets the runtime is called managed
code; it benefits from features such as cross-language integration, cross-language
exception handling, enhanced security, versioning and deployment support, a simplified
model for component interaction, and debugging and profiling services.
18.using directive VS using statement
You create an instance in a using statement to ensure that Dispose is called on the object
when the using statement is exited. A using statement can be exited either when the end
of the using statement is reached or if, for example, an exception is thrown and control
leaves the statement block before the end of the statement.The using directive has two
uses:
a.Create an alias for a namespace (a using alias).
b.Permit the use of types in a namespace, such that, you do not have to qualify the use of
a type in that namespace (a using directive).
19.Describe the Managed Execution Process?
The managed execution process includes the following steps:
a.Choosing a compiler. To obtain the benefits provided by the common language
runtime, you must use one or more language compilers that target the runtime.
b.Compiling your code to Microsoft intermediate language (MSIL). Compiling translates
your source code into MSIL and generates the required metadata.
c.Compiling MSIL to native code. At execution time, a just-in-time (JIT) compiler
translates the MSIL into native code. During this compilation, code must pass a
verification process that examines the MSIL and metadata to find out whether the code
can be determined to be type safe.
d.Executing your code. The common language runtime provides the infrastructure that
enables execution to take place as well as a variety of services that can be used during
execution.
20.How Garbage Collector (GC) Works?
The methods in this class influence when an object is garbage collected and when
resources allocated by an object are released. Properties in this class provide information
about the total amount of memory available in the system and the age category, or
generation, of memory allocated to an object. Periodically, the garbage collector performs
garbage collection to reclaim memory allocated to objects for which there are no valid
references. Garbage collection happens automatically when a request for memory cannot
be satisfied using available free memory. Alternatively, an application can force garbage
collection using the Collect method.Garbage collection consists of the following steps:
a.The garbage collector searches for managed objects that are referenced in managed
code.
b.The garbage collector attempts to finalize objects that are not referenced.
c.The garbage collector frees objects that are not referenced and reclaims their memory.
21.Why do we need to call CG.SupressFinalize?
Requests that the system not call the finalizer method for the specified object. [C#]public
static void SuppressFinalize( object obj); The method removes obj from the set of objects
that require finalization. The obj parameter is required to be the caller of this
method.Objects that implement the IDisposable interface can call this method from the
IDisposable.Dispose method to prevent the garbage collector from calling Object.Finalize
on an object that does not require it.
22.What is nmake tool?
The Nmake tool (Nmake.exe) is a 32-bit tool that you use to build projects based oncommands contained in a .mak file.usage
9.What is Code Access Security (CAS)?CAS is the part of the .NET security model that determines whether or not a piece ofcode is allowed to run, and what resources it can use when it is running. For example, itis CAS that will prevent a .NET web applet from formatting your hard disk.How does CAS work?
The CAS security policy revolves around two key concepts - code groups andpermissions. Each .NET assembly is a member of a particular code group, and each codegroup is granted the permissions specified in a named permission set. For example, usingthe default security policy, a control downloaded from a web site belongs to the 'Zone -Internet' code group, which adheres to the permissions defined by the 'Internet' namedpermission set. (Naturally the 'Internet' named permission set represents a very restrictiverange of permissions.)
Who defines the CAS code groups?Microsoft defines some default ones, but you can modify these and even create your own.To see the code groups defined on your system, run 'caspol -lg' from the command-line.
10.Which namespace is the base class for .net Class library?
Ans: system.object
11.What are object pooling and connection pooling and difference?
Where do we setthe Min and Max Pool size for connection pooling?Object pooling is a COM+ service that enables you to reduce the overhead of creatingeach object from scratch. When an object is activated, it is pulled from the pool. Whenthe object is deactivated, it is placed back into the pool to await the next request. You canconfigure object pooling by applying the ObjectPoolingAttribute attribute to a class thatderives from the System.EnterpriseServices.ServicedComponent class. Object poolinglets you control the number of connections you use, as opposed to connection pooling,where you control the maximum number reached.Following are important differencesbetween object pooling and connection pooling:Creation. When using connection pooling, creation is on the same thread, so if there isnothing in the pool, a connection is created on your behalf. With object pooling, the poolmight decide to create a new object. However, if you have already reached yourmaximum, it instead gives you the next available object. This is crucial behavior when ittakes a long time to create an object, but you do not use it for very long.Enforcement of minimums and maximums. This is not done in connection pooling. Themaximum value in object pooling is very important when trying to scale your application.You might need to multiplex thousands of requests to just a few objects. (TPC/Cbenchmarks rely on this.)COM+ object pooling is identical to what is used in .NET Framework managed SQLClient connection pooling. For example, creation is on a different thread and minimumsand maximums are enforced.
12.What is Application Domain?
The primary purpose of the AppDomain is to isolate an application from otherapplications. Win32 processes provide isolation by having distinct memory addressspaces. This is effective, but it is expensive and doesn't scale well. The .NET runtimeenforces AppDomain isolation by keeping control over the use of memory - all memoryin the AppDomain is managed by the .NET runtime, so the runtime can ensure thatAppDomains do not access each other's memory.Objects in different application domainscommunicate either by transporting copies of objects across application domainboundaries, or by using a proxy to exchange messages.MarshalByRefObject is the baseclass for objects that communicate across application domain boundaries by exchangingmessages using a proxy. Objects that do not inherit from MarshalByRefObject areimplicitly marshal by value. When a remote application references a marshal by valueobject, a copy of the object is passed across application domain boundaries.
How does an AppDomain get created?
AppDomains are usually created by hosts. Examples of hostsare the Windows Shell, ASP.NET and IE. When you run a .NET application from thecommand-line, the host is the Shell. The Shell creates a new AppDomain for everyapplication.AppDomains can also be explicitly created by .NET applications. Here is aC# sample which creates an AppDomain, creates an instance of an object inside it, andthen executes one of the object's methods.
13.What is serialization in .NET?
What are the ways to control serialization?Serialization is the process of converting an object into a stream of bytes. Deserializationis the opposite process of creating an object from a stream of bytes.Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), orto persist objects (e.g. to a file or database).Serialization can be defined as the process ofstoring the state of an object to a storage medium. During this process, the public andprivate fields of the object and the name of the class, including the assembly containingthe class, are converted to a stream of bytes, which is then written to a data stream. Whenthe object is subsequently deserialized, an exact clone of the original object is created.Binary serialization preserves type fidelity, which is useful for preserving the state of anobject between different invocations of an application. For example, you can share anobject between different applications by serializing it to the clipboard. You can serializean object to a stream, disk, memory, over the network, and so forth. Remoting usesserialization to pass objects "by value" from one computer or application domain toanother.XML serialization serializes only public properties and fields and does not preserve typefidelity. This is useful when you want to provide or consume data without restricting theapplication that uses the data. Because XML is an open standard, it is an attractive choicefor sharing data across the Web. SOAP is an open standard, which makes it an attractivechoice. There are two separate mechanisms provided by the .NET class library -XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer forWeb Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are availablefor use in your own code.
14.Why do I get errors when I try to serialize a Hashtable?
XmlSerializer will refuse to serialize instances of any class that implements IDictionary,e.g. Hashtable. SoapFormatter and BinaryFormatter do not have this restriction.
15.What is exception handling?
When an exception occurs, the system searches for the nearest catch clause that canhandle the exception, as determined by the run-time type of the exception. First, thecurrent method is searched for a lexically enclosing try statement, and the associatedcatch clauses of the try statement are considered in order. If that fails, the method thatcalled the current method is searched for a lexically enclosing try statement that enclosesthe point of the call to the current method. This search continues until a catch clause isfound that can handle the current exception, by naming an exception class that is of thesame class, or a base class, of the run-time type of the exception being thrown. A catchclause that doesn't name an exception class can handle any exception.Once a matchingcatch clause is found, the system prepares to transfer control to the first statement of thecatch clause. Before execution of the catch clause begins, the system first executes, inorder, any finally clauses that were associated with try statements more nested that thanthe one that caught the exception. Exceptions that occur during destructor execution areworth special mention. If an exception occurs during destructor execution, and thatexception is not caught, then the execution of that destructor is terminated and thedestructor of the base class (if any) is called. If there is no base class (as in the case of theobject type) or if there is no base class destructor, then the exception is discarded.
Dot Nte Interview Questions
1. What is .NET Framework?
The .NET framework created by Microsoft is a software development platform focused
on rapid application development, platform independence and network transparency.
.NET is Microsoft's strategic initiative for server and desktop development for the next
decade. According to Microsoft, .NET includes many technologies that are designed to
facilitate rapid development of Internet and intranet applications.
2. Is .NET a runtime service or a development platform?
It's both and actually a lot more. Microsoft .NET includes a new way of delivering
software and services to businesses and consumers. A part of Microsoft.NET is the .NET
Frameworks. The .NET frameworks SDK consists of two parts: the .NET common
language runtime and the .NET class library. In addition, the SDK also includes
command-line compilers for C#, C++, JScript, and VB. You use these compilers to build
applications and components. These components require the runtime to execute so this is
a development platform.
3.What is a IL? or what is MSIL?What is JIT?
(IL)Intermediate Language is also known as MSIL (Microsoft Intermediate Language) or
CIL (Common Intermediate Language). All .NET source code is compiled to IL. This IL
is then converted to machine code at the point where the software is installed, or at run-
time by a Just-In- Time (JIT) compiler.
4. Can we write IL programs directly?
Yes.
assembly
MyAssembly {
}
.class MyApp {
.method static void Main() {
.entrypoint ldstr "Hello, IL!" call
void System.Console::WriteLine(class System.Object)
ret }
}
Just put this into a file called hello.il, and then run ilasm hello.il. An exe assembly will be
generated.Can I do things in IL that I can't do in C#?Yes. A couple of simple examples
are that you can throw exceptions that are not derived from System.Exception, and you
can have non-zero-based arrays.
5.What is JIT (just in time)?
how it works?Before Microsoft intermediate language (MSIL) can be executed, it must
be converted by a .NET Framework just-in-time (JIT) compiler to native code, which is
CPU-specific code that runs on the same computer architecture as the JIT compiler.
Rather than using time and memory to convert all the MSIL in a portable executable (PE)
file to native code, it converts the MSIL as it is needed during execution and stores the
resulting native code so that it is accessible for subsequent calls.The runtime supplies
another mode of compilation called install-time code generation. The install-time code
generation mode converts MSIL to native code just as the regular JIT compiler does, but
it converts larger units of code at a time, storing the resulting native code for use when
the assembly is subsequently loaded and executed.As part of compiling MSIL to native
code, code must pass a verification process unless an administrator has established a
security policy that allows code to bypass verification. Verification examines MSIL and
metadata to find out whether the code can be determined to be type safe, which means
that it is known to access only the memory locations it is authorized to access.
6. What is strong name?
A name that consists of an assembly's identity—its simple text name, version number,
and culture information (if provided)—strengthened by a public key and a digital
signature generated over the assembly.
7. What is portable executable (PE)?
The file format defining the structure that all executable files (EXE) and Dynamic Link
Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is
derived from the Microsoft Common Object File Format (COFF). The EXE and DLL
files created using the .NET Framework obey the PE/COFF formats and also add
additional header and data sections to the files that are only used by the CLR. The
specification for the PE/COFF file formats is available at
http://www.microsoft.com/whdc/hwdev/hardware/pecoffdown.mspx
8.What is Event - Delegate?
The event keyword lets you specify a delegate that will be called upon the occurrence of
some "event" in your code. The delegate can have one or more associated methods that
will be called when your code indicates that the event has occurred. An event in one
program can be made available to other programs that target the .NET Framework
Common Language Runtime.// keyword_delegate.cs// delegate declarationdelegate void
MyDelegate(int i);class Program
{
public static void Main()
{
TakesADelegate(new MyDelegate(DelegateFunction));
}
public static void TakesADelegate(MyDelegate SomeFunction)
{
SomeFunction(21);
}
public static void DelegateFunction(int i)
{
System.Console.WriteLine("Called by delegate with number: {0}.", i);
}
}