Interview Questions - Difficulty Level - I

0 comments

 What is the default access specifier of a class ?.
Internal.

 Can strings be declared as constants in C#?.
Yes strings can be declared as constants.strings get a
special treatment even though the general diktat is against this.
All primitive types and strings can be declared as constants.

Public const string name="CSHARP";


 What is the default access specifier of a class member.
Private;


 Can Constructors be declared as Private?.
Yes.Constructors can be declared as private.


 How to force a Garbage Collection ?.
Garbage collection can be forced by invoking the static
method.GC.Collect(0);Generation value is passed as the
parameter.Here zero stands for generation zero.


 Does C# support multiple inheritance ?.
C# doesn't support multiple inheritance.


 Does C# support dynamic typing ?.
Yes.Dynamic typing is supported.
Syntax dynamic dynVar="name"; dynVar=23;


 Can value type be assigned a null value?.If so how?
Yes value type can be nullable in c#.
Syntax int ?number = null;

 Where does value and reference types are strored in memory?
Stack and Heap respectively.


 Give one example for compile time polymorphism ?.
Method Overloading.


 Which datatype is used to store a arbitrarily huge numeric value ?.
System.Numerics.BigInteger


 What is the difference between const and readonly ?.
A Value for a constant is decided during compile time.
This means all constant values are required to be literals
.Quite oppositely a readonly is initialized during runtime
 and cannot be modified thereafter.A readonly can be
initialized only in the constructor of a class.A reassignment
of a readonly is illegal.Always prefer a readonly over
a constant as readonly is more flexible.


 Which area of Memory is managed by runtime?.Stack or Heap
Heap


 What is the use of keyword var?.
var achieves what is known as implicit typing. When a variable is declared as var,the underlying datatype is discovered during compile time. Its mainly used for storing linq results,as the type of object returned from a linq query is not known until compile time.


 Is it possible to call Finalize method manually?.What is the use of this method?
No.Its not possible.Only the runtime has previlege to invoke this.The method is automatically invoked to clear off any unmanaged resources(network,windows handle) used in the program.But still its the developer responsibility to write the clean up code inside finalize().


 Which is type safe ArrayList or List<T>
List<T> is Type Safe.


 What is the difference between List<T> and SortedList<T>
They both are similar datastructures except for one feature.SortedList will have its elements stored in a sorted order. when a new element is inserted its exact position is calculated and then inserted.This means recalculating the position for other elements on the list. The overhead involved in SortedList<T> is high compared to List<T>.Otherwise they both have similar capabilities.