Showing posts with label .Net Interview Question With Answer. Show all posts
Showing posts with label .Net Interview Question With Answer. Show all posts

Can multiple catch blocks be executed for a single try statement?

No. Once the proper catch block processed, control is transferred to the finally block (if there are any).

What’s the .NET collection class that allows an element to be accessed using a unique key?

HashTable.

How can you sort the elements of the array in descending order?

By calling Sort() and then Reverse() methods.

What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.

Can you store multiple data types in System.Array?

Ans: No

# What’s the difference between System.String and System.Text.StringBuilder classes?

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

what is the difference between Convert.toString and .toString ()?

Just to give an understanding of what the above question means see the below code.
int i =0;
MessageBox.Show(i.ToString());
MessageBox.Show(Convert.ToString(i));
We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what is the
difference. The basic difference between them is “Convert” function handles NULLS while
“i.ToString()” does not it will throw a NULL reference exception error. So as a good coding
practice using “convert” is always safe.

How to prevent my .NET DLL to be decompiled?

By design, .NET embeds rich Meta data inside the executable code using MSIL. Any one can
easily decompile your DLL back using tools like ILDASM (owned by Microsoft) or Reflector for
.NET which is a third party. Secondly, there are many third party tools, which make this
decompiling process a click away. So any one can easily look in to your assemblies and reverse
engineer them back in to actual source code and understand some real good logic, which can
make it easy to crack your application.
The process by which you can stop this reverse engineering is using “obfuscation”. It is a
technique, which will foil the decompilers. Many third parties (XenoCode, Demeanor for .NET)
provide .NET obfuscation solution. Microsoft includes one that is Dotfuscator Community
Edition with Visual Studio.NET.

What is CODE Access security?

CAS is part of .NET security model that determines whether a piece of code is allowed to run and
what resources it can use while running. Example CAS will allow an application to read but not
to write and delete a file or a resource from a folder..

what is the difference between System exceptions and Application

All exception derives from Exception Base class. Exceptions can be generated programmatically
or can be generated by system. Application Exception serves as the base class for all applicationspecific
exception classes. It derives from Exception but does not provide any extended
functionality. You should derive your custom application exceptions from Application Exception.
Application exception is used when we want to define user-defined exception, while system
exception is all that is defined by .NET.

What is the difference between VB.NET and C#?

Well this is the most debatable issue in .NET community and people treat languages like religion.
It is a subjective matter which language is best. Some like VB.NET’s natural style and some like
professional and terse C# syntaxes. Both use the same framework and speed is very much
equivalents. Still let us list down some major differences between them:-
Advantages VB.NET:-
• Has support for optional parameters that makes COM interoperability much easy.
• With Option Strict off late binding is supported.Legacy VB functionalities can be
used by using Microsoft.VisualBasic namespace.
• Has the WITH construct which is not in C#.
• The VB.NET parts of Visual Studio .NET compiles your code in the background.
While this is considered an advantage for small projects, people creating very
large projects have found that the IDE slows down considerably as the project
gets larger.
Advantages of C#
• XML documentation is generated from source code but this is now been
incorporated in Whidbey.
• Operator overloading which is not in current VB.NET but is been introduced in
Whidbey.
• Use of this statement makes unmanaged resource disposal simple.
• Access to Unsafe code. This allows pointer arithmetic etc, and can improve
performance in some situations. However, it is not to be used lightly, as a lot of
the normal safety of C# is lost (as the name implies).This is the major difference
that you can access unmanaged code in C# and not in VB.NET.

What are Value types and Reference types?


Value types directly contain their data that are either allocated on the stack or allocated in-line in
a structure. So value types are actual data.
Reference types store a reference to the value's memory address, and are allocated on the heap.
Reference types can be self-describing types, pointer types, or interface types. You can view
reference type as pointers to actual data.
Variables that are value types each have their own copy of the data, and therefore operations on
one variable do not affect other variables. Variables that are reference types can refer to the same
object; therefore, operations on one variable can affect the same object referred to by another
variable. All types derive from the System. Object base type.

(A) What are different types of JIT?


JIT compiler is a part of the runtime execution environment.
In Microsoft .NET there are three types of JIT compilers:
• Pre-JIT: - Pre-JIT compiles complete source code into native code in a single
compilation cycle. This is done at the time of deployment of the application.
• Econo-JIT: - Econo-JIT compiles only those methods that are called at runtime.
However, these compiled methods are removed when they are not required.
• Normal-JIT: - Normal-JIT compiles only those methods that are called at runtime.
These methods are compiled the first time they are called, and then they are stored in
cache. When the same methods are called again, the compiled code from cache is used
for execution.

What is reflection?


All .NET assemblies have metadata information stored about the types defined in modules. This
metadata information can be accessed by mechanism called as “Reflection”. System. Reflection
can be used to browse through the metadata information.
Using reflection, you can also dynamically invoke methods using System.Type.Invokemember.
Below is sample source code if needed you can also get this code from CD provided, go to
“Source code” folder in “Reflection Sample” folder.
Public Class Form1
Private Sub Form1_Load (ByVal sender As System. Object, ByVal e as
System.EventArgs) Handles MyBase.Load
Dim Pobjtype As Type
Dim PobjObject As Object
Dim PobjButtons As New Windows.Forms.Button ()
Pobjtype = PobjButtons.GetType ()
For Each PobjObject in Pobjtype.GetMembers
LstDisplay.Items.Add (PobjObject.ToString ())
Next
End Sub
End Class

What is garbage collection?

Garbage collection is a CLR feature, which automatically manages memory. Programmers forget to release the objects while coding ... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. We should avoid using destructors because before GC destroys the object it first executes destructor in that case it will have to wait for code to release the unmanaged resource. This results in additional delays in GC. So it is recommended to implement IDisposable interface, write cleanup code in Dispose method, and call GC.SuppressFinalize method. Its like instructing GC not to call your constructor.

What is serialisation and deserialisation?

Serialization is the process of converting an object instance’s state into a sequence of bits that can then be written to a stream or some other storage medium.

Deserialization is the process of converting a serialized bit stream to an instance of an object type.

The .NET Framework provides an easy-to-use serialization mechanism for object implementers. To make a class, structure, delegate, or enumeration serializable, simply attribute it with the SerializableAttribute custom attribute, as shown in the following code snippet:

[Serializable]
class SomeClass
{
public int m_public = 5000;
private int m_private = 5001;
}

Because we’ve attributed the SomeClass type with the SerializableAttribute, the common language runtime will automatically handle the serialization details for us.

Also To prevent the serialization of a field member of a type attributed with the SerializableAttribute, you can attribute the field member with the NonSerializedAttribute.

What is serialisation and deserialisation?

Serialization is the process of converting an object instance’s state into a sequence of bits that can then be written to a stream or some other storage medium.

Deserialization is the process of converting a serialized bit stream to an instance of an object type.

The .NET Framework provides an easy-to-use serialization mechanism for object implementers. To make a class, structure, delegate, or enumeration serializable, simply attribute it with the SerializableAttribute custom attribute, as shown in the following code snippet:

[Serializable]
class SomeClass
{
public int m_public = 5000;
private int m_private = 5001;
}

Because we’ve attributed the SomeClass type with the SerializableAttribute, the common language runtime will automatically handle the serialization details for us.

Also To prevent the serialization of a field member of a type attributed with the SerializableAttribute, you can attribute the field member with the NonSerializedAttribute.

How will you get result from two table in SqlDataReader ?

Syntax:

string str="Select * from table1;Select * from table2";
cmd.commandtext=str;
dr=cmd.executereader();

What is the difference in using IP address and DNS name in the connection string while connecting to SQL database?

When we are making connection string always use Server's IP address not the DNS name if we use IP address it will reduce the time taken for connection to establish.

Because server IP address is used to get a default or named instance of Sql Server that ls running. if we are running the cluster we have to use the Virtual SQL Server IP address.

What are the differences between Datalist DataGrid and datarepeater ?

DataList

* Has table appearance by default
* Has no auto format option
* has no default paging & sorting options
* can define separators between elements using template

DataGrid

* Has a grid appearance by default
* has a auto format option
* has default paging and sorting
* has no separator between elements

DataRepeater

* simple,read-only output, has no built in support for selecting or editing items, has no default appearance, has no default paging.