.NET Framework Interview Questions and Answers (547) - Page 16

Difference between a Class and Component?

Class is a datatype that encloses data and function members.
It can be used for implementing the various OOPS features.
Component is a particular class that must implement the IComponent interface .It is the base class for all components in the common language runtime that marshal by reference. Component is remotable and derives from the MarshalByRefObject class.
IComponent interface belongs to System.ComponentModel namespace.

So, we can say Component is subclassification of a class
Difference between event and delegate?

event:

1) It is a data member of a type(class/structure)

2)It is declared inside a type(class/structure)

3) It is used to generate notifications which are then passed to methods though
delegates.

delegate:

1)It is a datatype(reference type) that holds references of methods with
some signatures.also called as function pointer.

2)It may or may not be declared inside a class.

3)It is used as the return type of an event and used in passing messages from event to methods.


event-->delegate-->method
example:
namespace dd
{
//delegate declaration
delegate void first();
class cc
{
//event declaration
public first myevent;
}
}

example 2:
button1.Click+=new EventHandler(this.button1_Click);
(Windows Applications)

Click is the event that returns an instance of the EventHandler delegate.
EventHandler delegate has the reference of button1_Click event and that
helps in the communication betwen the Click event and button1_Click method

Is versioning applicable to private assemblies?

Yes, versioning is applicable to private assemblies too

There are 2 types of versions:
1)File version
2)Assembly version

File version is the default version that is assigned to any .NET assembly

example: click a .exe and view its properties: File version would always be there

Assembly version is applicable when we create a shared assembly(assembly installed

in a GAC)


Private assemblies do not have Assembly version, but they do have File Version
What is Application Domain?

It is the execution boundary within which an application runs.
Application Domain is created inside a process.
One process can have multiple Application Domains.

Example:

Consider a Remoting scenario:

2 exe's of the client and the server are communicating with each other.

2 Application Domains will be created in the process of the server.

Process: In this case, it is the executable of the Operating System that will control the interaction of the client and server exe's.
the 2 exes's run in their Application Domains that will be created in the
execution area(in the RAM) of the OS exe.


Application Domains provide the isolation of the 2 exe's(i.e. the client and the
server).
What is Constructor Chaining?

We can chain the call of constructor from child class to base class depending on our requirement. This concept makes sure that the matching base class constructor must be called based on the parameter passed to the child class constructor.

Example:

namespace ConsoleApplication1

{
class A
{
public A(){
Console.WriteLine("Constructor A.");
}
public A(string s){
Console.WriteLine("Constructor A with parameter = {0}",s);
}
public A(string s,string t){
Console.WriteLine("Constructor A with parameter = {0} & {1}", s,t);
}
}

class B:A
{
public B():base(){
Console.WriteLine("Constructor B.");
}
public B(string s):base(s){
Console.WriteLine("Constructor B with parameter = {0}", s);
}
public B(string s, string t):base(s,t){
Console.WriteLine("Constructor B with parameter = {0} & {1}", s, t);
}
}
class Program
{
static void Main(string[] args)
{
B b1 = new B();
B b2 = new B("First Parameter ", "Second Parameter");

Console.Read();
}
}
}


Output:
Constructor A.
Constructor B.
Constructor A with parameter = First Parameter & Second Parameter
Constructor B with parameter = First Parameter & Second Parameter
How many languages a .NET DLL can contain?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following namespaces spans across multiple assemblies?

NOTE: This is objective type question, Please click question title for correct answer.
What does a method's signature consist of?

NOTE: This is objective type question, Please click question title for correct answer.
What is an assembly manifest?

The assembly manifest is providing information to the .NET application at runtime. It provides the information like assembly's name, version, requested permissions, and other assemblies that the .NET application references.

It describes the assembly to the managed hosting environment.

It acts as a directory to the modules, types, and resources in the assembly.
What is an application manifest?

The application manifest which gives information to the operating system, such as in which way the assembly should be deployed and will check whether administrative elevation is required or not.

This is processed before the .NET-managed hosting environment loads to the assembly.
You are creating emp class whose objects need to be sorted when in an ArrayList collection. How can you do that?

NOTE: This is objective type question, Please click question title for correct answer.
Which of these gives us the method name that throws the current exception?

NOTE: This is objective type question, Please click question title for correct answer.
Which of these classes can be used to write string data?

NOTE: This is objective type question, Please click question title for correct answer.
Which of these components can be used for printing?

NOTE: This is objective type question, Please click question title for correct answer.
Difference between lock and Monitor.Enter()

lock keyword basically provides a shortcut to Enter method of Monitor class.
Monitor is used to provide thread synchronization.It means till the Thread in which the method is being used finishes its task, no other thread can access the object.

example:

lock (object)
{

}

It is compiled into

Monitor.Enter(object);
try
{
//code
}
finally
{
Monitor.Exit(object);
}

See the MSIL of the assembly.

We can write much more code and perform customization in the try block.
How can you write to a File System?

NOTE: This is objective type question, Please click question title for correct answer.
How can you store decimals data precisely from .NET?

NOTE: This is objective type question, Please click question title for correct answer.
Can you install multiple assemblies together?

Yes, we can install multiple assemblies together

use installutil command

example: installutil Assembly1.exe Assembly2.exe.
It will install both the Assemblies in a transactional manner. if installation of one
of the assemblies fail, the installation of the other assembly will be rolled back.
Difference between Assembly.LoadFrom() and Assembly.LoadFile() methods?

Both methods are used to load the assemblies. we can then extract all the metatdata of the assembly using Reflection.

Difference:

1)LoadFrom can use either the name or the path of the assembly,
LoadFile will expect the path of the assembly(see the overloaded versions)

2)LoadFrom uses a probing algorithm to find the assembly.f if you have two assemblies that have the same identity but different locations, you can get some unexpected behavior.But using LoadFile, you can load the desired assembly as needed.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories