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

Which of these collections uses keys to uniquely identify the data?

NOTE: This is objective type question, Please click question title for correct answer.
What is difference between out and ref in c#?

This is a great .NET Interview question and also very very confusing question. By default parameters are always passed by value to methods and functions.If you want to pass data byref then you can use either out or ref keyword.

There are two big difference between these keywords one is the way data is passed between the caller code and method and second who is responsible for initialization.

Way the data is passed(directional or bi-directional)
==================================================
When you use OUT data is passed only one way i.e from the method to the caller code.
When you use REF , Data can be passed from the called to the method and also vice versa.

Who initializes data
==============================================
In OUT the variables value has to be intialized in the method. In REF the value is initialized outside the method by the caller.

The most important thing the interviewer will like to hear from you When to use when
======================================================
OUT will be used when you want data to be passed only from the method to the caller.
REF will be used when you want data to be passed from the called to the method and also vice versa.

My 100 .NET Interview questions http://www.questpond.com
What is .NET Framework?

.NET (.Network Enabled Technologies) is a collection of development tools
developed by the Microsoft Corporation that enables the developers to develop
and execute a large variety of applications

example: Console,Windows,Web,WPF,WCF, Web Services, Window Services,
Mobile Applications.

.NET Framework consists of:

1)CLR: (Common Language Runtime):

2)FCL: (Framework Class Llivraries)

3)Languages, Language Compilers

CLR is the set of components(also called as the execution engine) and provides
us with many runtime services.
example:
1)Managing code execution.
2)Menory management and Garbage Collection.
3)Exception handling management
4)Security and Code Verification
5)MultiThreading support
6)Cross Language interoperability using CTS and CLS.

FCL provides us with the predefined class libraries which have over thousands of

classes that can be used in development and execution.

example: System.Data.dl
System.Windows.Forms.dll
System.dll

mscorlib.dll

Languages :example: VB.NET, C#,VC++

Each language ahs its own set of compilers
ex: vbc for vb.net, csc for csharp.
Coompilers are used to compile the code and generate the executable files.(Assemblies)
What is CLS?

CLS:

Common Language Specification:

It is a set of the programming rules which every .NET language must follow.

CLS is used so that the code written in one language is interoperable with the code written in another language. The different .NET languages code is compiled into MSIL Code. CLS defines the infrastructure for the MSIL Code. The CLR processes the MSIL code and help in its execution. This ensures the language interoperability.


EXAMPLES OF CLS:

1)Common set of data types for all the languages( CTS)

Int32 datatype is implemented as int in C# and as integer in VB.NET

2)Interfaces cannot have static methods.It applies to all the .NET languages.

The Types which follow the CLS rules are also called as CLS Compliant types.

CLS compliant languages:

VB.NET,C#, VC++

Use of CLS:

A class written in VB.NET can be used in C# and vice-versa.


For the complete list of CLS features, please visit this link.


http://msdn.microsoft.com/en-us/library/12a7a7h3(VS.71).aspx
Which of these is a valid path declaration?

NOTE: This is objective type question, Please click question title for correct answer.
Differences between method overloading and method overriding

Method Overloading and Method Overriding are both the techniques used to implement FUNCTIONAL POLYMORPHISM
They enhance the methods functionality using their respective features.

overloading:
1) It involves having another method with the same name in a class or its derived class.

2)can be implemented with or without inheritance.

3)It is implemented by:

a)changing the number of parameters in different methods with same name.

b)changing the parameter data types (if the number of parameters are same)

c)changing parameter order.

4)applicable to static as well as non static methods:

5)no keywords needed before the method names in C#.

6)also called as COMPILE TIME Polymorphism.
example: int add(int a, int b)
{
return a+b;
}
int add(int a)
{
return a*5;
}




Overriding:

1) It involves having another method with the same name in a base class and derived class.

2)always needs inheritance.

3)It is implemented by having two methods with same name, same signature, but different implementations (coding)in a base class and derived class

4)applicable to nonstatic, nonprivate methods only.access modifiers of the methods are not changed in the base and derived classes.

5)virtual and override keywords are needed before the method names in base and derived classes.
For overriding in firther classes, override keyword will be used,

6)RUN TIME Polymorphism
example:
class A
{
public virtual void demo()
{

}
}
class B:A
{
public override void demo()
{

}
static void Main()
{
B obj=new B();
obj.demo();
}
}
Which namespace defines the collection classes?

Collection classes are defined by 2 namespaces

1)System.Collections:

defines ArrayList, Stack, Queue

2)System.Collections.Generic

Defines the Generic Collections

example: List<>,Stack<>, Queue<>
Difference between an Assembly and DLL

An assembly is basically a file that contains the MSIL Code and Metadata.
It is the smallest unit of deployment of .NET applications.
An assembly in .NET has 2 extensions (.exe and .dll)

dll : dynamic link library.
So, we can say a dll is an assembly, but an assembly may not always be a dll

In other words, dll is one type of an assembly
OOP .NET Interview question :- What is Polymorphism?

This is a nice and simple OOP interview question.

As the name says POLY (Many) MORPHISM (Change). Polymorphism is the ability of the object to behave differently under different conditions. For instance a simple user object can behave as a admin user or as a simple user depending on conditions.

There are two ways of doing polymorphism dynamic and static. Static polymorphism is achieved by using method overloading and dynamic polymorphism is achieved by using method overriding. Please note do confuse with overloading and overriding while answering this question. Many .NET developers make a nice versa statement leading to lot of confusion.

.NET interview question and answer http://www.questpond.com
What is MSIL?

MSIL : Microsoft Intermediate Language

Definition:
It is a set of CPU independent instructions that are generated by the language compiler when the project is compiled. MSIL code is not executable but further
processed by CLR/other runtime environments before it becomes executable.
MSIL is contained in the assembly of the .NET application.

Features:
MSIL instructions map to the code that is written in .NET Language and are used for loading, storing, initializing, and
calling methods on objects, as well as for
arithmetic and logical operations, control flow, direct
memory access, exception handling, and other operations.

CLS(Common language Specification) provides the infrastructure for MSIL.


Benefits:

1)MSIL provides language interoperability as the code in any .NET language is compiled into MSIL.

2)Same performance for all the .NET Languages:

3)Support for different runtime environments:

CLR can understand MSIL.

Non .NET environments also support MSIL.
-----------------------------------------------------------

The JIT Compiler in CLR converts the MSIL code into native machine code which is then executed by the OS
Difference between Finalize and Dispose methods ?

Finalize and Dispose are both known as Finalizers.

They are the methods used to deallocate the memory of the objects
Differences:

FINALIZE

1)Finalize belongs to the Object class.

2)It is automatically called by the Garbage Collection mechanism when the object goes out of the scope(usually at the end of the program)
It is not called by the User Code.

In C#, suppose there is a class known as emp

class emp
{
//This is the destructor of emp class
~emp()
{

}
//This destructor is implicitly compiled to the Finalize method.
}

3)Not suitable for instant disposing of the objects.Sloer method.


DISPOSE

1)Dispose belongs to the IDisposable interface

2)we have to manually write the code to implement it(User Code)
ex: if we have emp class we have to inherit it from the IDisposable interface
and write code. We may have to suppress the Finalize method using GC.SuppressFinalize() method.

3)Faster method for instant disposal of the objects

Example: user interface Controls. Forms, SqlConnection class have built in implementaion of Dispose method.
How many classes a dll can contain?

There is no limit.
However, it depends upon the hardware space available and the performance
related parameters.
What is Serialization?

Serialization:

It is the process through which we can convert an object into a format that can be persisted or transported.
During this process, the public and private fields of the object and the name of the class,including the assembly containing the class, are converted to a stream of bytes,
which is then written to a data stream.
Serialization allows us to save the state of objects from memory to files.
It is most commonly used in Web Services/Remoting applications.
Can abstract class have constructors?

Yes, an abstract class does have a constructor.
It will be called when it subclass is instantiated.

example:
abstract class bank

{
public bank()
{
Console.WriteLine("bank");
}

}
class icici : bank
{
icici()
{
Console.WriteLine("icici");
}
static void Main()
{
bank b = new icici();

}
}


//Output:

when the object of icici class is created,
They will be displayed in the output.
bank
icici
Difference between String.Empty and ""

String.Empty is a readonly field, while "" is a constant
Consider this code snippet.

private void button1_Click(object sender, EventArgs e)

{
string s = textBox1.Text;
switch (s)
{
case String.Empty:
MessageBox.Show("blank");
break;
}


}


//Compiler will generate an error
//A constant value is expected

//So, if we use "" in place of String.Empty, no error will be generated.
Difference between Environment.MachineName, SystemInformation.ComputerName and Dns.GetHostName


Environment.MachineName :


Environment is a class defined by System Namespace.
MachineName is its property.

It reads the NetBIOS name of local computer..

SystemInformation.ComputerName :


SystemInformation is a class defined by System.Windows.Forms Namespace
ComputerName is its property,

output:
Same as Environment.MachineName


Dns.GetHostName :


Dns is a class defined by System.Net namespace:
GetHostName is its method.

It gets host name of computer which refers to a domain name that has one or more associated IP adresses.

What will be the output of this code? using System; class A { class B { public string str = "welcome"; } } class Demo { static void Main() { B Obj = new B(); Console.WriteLine(Obj.str); } }

Answer:

The compiler will generate an error

The Type or Namespace 'B' could not be found.

It is because since B is the inner class, it is now private.

Solution:

1)we have to change the access modifier of B to internal/public

2)we have to give the full path of class B when creating the object

i.e. A.B obj=new A.B();
Then we can see the value of the field str in the output.
How can you specify the framework version targetted by your application?

In ASP.NET 4.0, we can write in web.config file like this:

A new attribute targetFramework has been added.

<?xml version="1.0"?>
<configuration>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
</configuration>
Which controls cannot be placed on an MDI Form?

These controls cannot be placed on the MDI Form

1)Components :

example: BackgroundWorker,
ImageList,
HelpProvider,
Timer

2)Printing:
example: PrintDocument, PrintDialog

3)Dialogs
example: ColorDialog,
SaveFileDialog

These controls are placed in the Component Tray window.
It is the window below the Form window anad can be viewed in Design mode
It contains all the controls which cannot be viewed even by default
when the application executes.

Difference between imperative and interrogative code.

Imperative code does not return a value. It just does performs an action.
example:

c#
void demo()
{
Console.WriteLine("welcme");

}

vb.net
sub procedures are imperative code.
sub dd()

end sub

Interrogative code does return a value.
c#
ex: int add(int a)
{
return a*5;
}

VB.NET FUNCTIONS
ex
function calc(byval a as integer) as integer
return a*5
end function
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