Tuesday 15 November 2011

C#.Net Interview Questions and Answers for freshers pdf


1.What is C#.Net?
C# (pronounced C Sharp) is a multi-paradigm programming language that encompases functional, imparitive, generic, Object-Oriented (class-based), and component-oriented programing disciplines. It was developed by Microsoft. C# is 44 programing languages supported by the .NET Frameworks.

2.What is the difference between realloc() and free()? 
The free subroutine frees a block of memory previously allocated by the malloc subroutine. Undefined results occur if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will occur. The realloc subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block.
The pointer specified by the Pointer parameter must have been created with the malloc, calloc, or realloc subroutines and not been deallocated with the free or realloc subroutines. Undefined results occur if the Pointer parameter is not a valid pointer.

3.What is function overloading and operator overloading?
Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler selects the proper function by examining the number, types and order of the arguments in the call. Function overloading is commonly used to create several  functions of the same name that perform similar tasks but on different data types.
Operator overloading allows existing C++ operators to be redefined so that they work on objects of user-defined classes.
Overloaded operators are syntactic sugar for equivalent function calls. They form a pleasant facade that doesn't add anything fundamental to the language (but they can improve understandability and reduce maintenance costs).

4.What is the difference between declaration and definition? 
The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g :
void stars ()
//function declaration
The definition contains the actual implementation.
E.g.:
void stars () // declarator
{
for(int j=10; j > =0; j--) //function body
cout << *;
cout << endl; }

5.What are the advantages of inheritance? 
It permits code reusability. Reusability saves time in program development. It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.

6.How do you write a function that can reverse a linked-list? 
void reverselist(void)
{
if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;
for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}
curnext->next = cur;
}
}

7.What do you mean by inline function?
The idea behind inline functions is to insert the code of a called function at the point where the function is called. If done carefully, this can improve the application's performance in exchange for increased compile time and possibly (but not always) an increase in the size of the generated binary executables.
Write a program that ask for user input from 5 to 9 then calculate the average
#include "iostream.h"
int main() {
int MAX = 4;
int total = 0;
int average;
int numb;
for (int i=0; i<MAX; i++) {
cout << "Please enter your input between 5 and 9: ";
cin >> numb;
while ( numb<5 || numb>9) {
cout << "Invalid input, please re-enter: ";
cin >> numb;
}
total = total + numb;
}
average = total/MAX;
cout << "The average number is: " << average << "\n";
return 0;
}
Write a short code using C++ to printout all odd number from 1 to 100 using a for
loop
for( unsigned int i = 1; i < = 100; i++ )
if( i & 0x00000001 )
cout << i << \",\";

8.What is public, protected, private? 
Public, protected and private are three access specifier in C++.
Public data members and member functions are accessible outside the class.
Protected data members and member functions are only available to derived classes.
Private data members and member functions can’t be accessed outside the class. However there is an exception can be using friend classes.
Write a function that swaps the values of two integers, using int* as the argument type.
void swap(int* a, int*b) 
{
int t;
t = *a;
*a = *b;
*b = t;
}

9.Tell how to check whether a linked list is circular?
Create two pointers, each set to the start of the list. Update each as follows:
while (pointer1) 
{
pointer1 = pointer1->next;
pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next;
if (pointer1 == pointer2) {
print (\"circular\n\");
}
}

10. OK, why does this work?
If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way,
it’s either 1 or 2 jumps until they meet.

11.What are the advantages of inheritance?
• It permits code reusability.
• Reusability saves time in program development.
• It encourages the reuse of proven and debugged high-quality software, thus reducing problem after a system becomes functional.

12.What is the difference between declaration and definition?
The declaration tells the compiler that at some later point we plan to present the definition of this declaration.
E.g: void stars () //function declaration
The definition contains the actual implementation.
E.g:
void stars () // declarator
{
for(int j=10; j>=0; j--) //function body
cout<<”*”;
cout<<endl; 
}

13.What is the difference between an ARRAY and a LIST?
Array is collection of homogeneous elements.
List is collection of heterogeneous elements.
For Array memory allocated is static and continuous.
For List memory allocated is dynamic and Random.
Array: User need not have to keep in track of next memory allocation.
List: User has to keep in Track of next location where memory is allocated.

14.What is a template? 
Templates allow to create generic functions that admit any data type as parameters and return value without having to overload the function with all the possible data types. Until certain point they fulfill the functionality of a macro. Its prototype is any of the two following ones:
template <class indetifier> function_declaration; template <typename indetifier> function_declaration;
The only difference between both prototypes is the use of keyword class or typename, its use is indistinct since both expressions have exactly the same meaning and behave exactly the same way.

15.Define a constructor - What it is and how it might be called? 
constructor is a member function of the class, with the name of the function being the same as the class name. It also specifies how the object
should be initialized.
Ways of calling constructor:
1) Implicitly: automatically by complier when an object is created.
2) Calling the constructors explicitly is possible, but it makes the code unverifiable.

16.Explain differences between eg. new() and malloc()? 
new() allocates continous space for the object instace
malloc() allocates distributed space.
new() is castless, meaning that allocates memory for this specific type,
malloc(), calloc() allocate space for void * that is cated to the specific class type pointer.

17.What is the difference between class and structure? 
Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality.
But C++ extended the structure to contain functions also. The major difference is that all declarations inside a structure are by default public.
Class: Class is a successor of Structure. By default all the members inside the class are private.

18.What is RTTI?
Runtime type identification (RTTI) lets you find the dynamic type of an object when you have only a pointer or a reference to the base type.
RTTI is the official way in standard C++ to discover the type of an object and to convert the type of a pointer or reference (that is, dynamic typing).
The need came from practical experience with C++. RTTI replaces many Interview Questions - Homegrown versions with a solid, consistent approach.

19.What is encapsulation? 
Packaging an object’s variables within its methods is called encapsulation.

20.What is an object? 
Object is a software bundle of variables and related methods. Objects have state and behavior.

21.How can you tell what shell you are running on UNIX system? 
You can do the Echo $RANDOM. It will return a undefined variable if you are from the C-Shell, just a return prompt if you are from the Bourne shell, and a 5 digit random numbers if you are from the Korn shell. You could also do a ps -l and look for the shell with the highest PID.

22.What do you mean by inheritance? 
Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.
Describe PRIVATE, PROTECTED and PUBLIC – the differences and give examples.
class Point2D
{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0), y(0) {}//default (no argument) constructor
};
Point2D MyPoint;
You cannot directly access private data members when they are declared (implicitly) private:
MyPoint.x = 5; // Compiler will issue a compile ERROR
//Nor yoy can see them:
int x_dim = MyPoint.x; // Compiler will issue a compile ERROR
On the other hand, you can assign and read the public data members:
MyPoint.color = 255; // no problem
int col = MyPoint.color; // no problem
With protected data members you can read them but not write them: MyPoint.pinned = true; // Compiler will issue a compile ERROR
bool isPinned = MyPoint.pinned; // no problem
What is namespace?
Namespaces allow us to group a set of global classes, objects and/or functions under a name. To say it somehow, they serve to split the global scope in sub-scopes known as namespaces.
The form to use namespaces is:
namespace identifier { namespace-body }
Where identifier is any valid identifier and namespace-body is the set of classes, objects and functions that are included within the namespace.
For example:
namespace general { int a, b; } In this case, a and b are normal variables integrated within the general namespace. In order to access to these variables from outside the namespace we have to use the scope operator ::. For example, to access the previous variables we would have to put:
general::a general::b
The functionality of namespaces is specially useful in case that there is a possibility that a global object or function can have the same name
than another one, causing a redefinition error.

23.What is a COPY CONSTRUCTOR and when is it called? 
A copy constructor is a method that accepts an object of the same class and copies it’s data members to the object on the left part of assignement:
class Point2D
{
int x; int y;
public int color;
protected bool pinned;
public Point2D() : x(0), y(0) {}//default (no argument) constructor
public Point2D( const Point2D & ) ;
};
Point2D::Point2D( const Point2D & p )
{
this->x = p.x;
this->y = p.y;
this->color = p.color;
this->pinned = p.pinned;
}
main()
{
Point2D MyPoint;
MyPoint.color = 345;
Point2D AnotherPoint = Point2D( MyPoint );
   // now AnotherPoint has color = 345
}
24.What is Boyce Codd Normal form? 
A relation schema R is in BCNF with respect to a set F of functional dependencies if for all functional dependencies in F+ of the form a-> ,
 where a and b is a subset of R, at least one of the following holds:
* a- > b is a trivial functional dependency (b is a subset of a)
* a is a superkey for schema R

25.What is virtual class and friend class? 
Friend classes are used when two or more classes are designed to work together and need access to each other's implementation in ways that the rest of the world shouldn't be allowed to have. In other words, they help keep private things private. For instance, it may be desirable for class DatabaseCursor to have more privilege to the internals of class Database than main() has.

26.What are 2 ways of exporting a function from a DLL?
1.Taking a reference to the function from the DLL instance.
2. Using the DLL ’s Type Library

27.What is the difference between an object and a class? 
Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.
- A Class is static. All of the attributes of a class are fixed before, during, and after the execution of a program. The attributes of a class don't change.
- The class to which an object belongs is also (usually) static. If a particular object belongs to a certain class at the time that it is created then it almost certainly will still belong to that class right up until the time that it is destroyed.
- An Object on the other hand has a limited lifespan. Objects are created and eventually destroyed. Also during that lifetime, the attributes of the object may undergo significant change.

28.What is a class? 
Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.

29.What is friend function? 
As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

30.What is abstraction? 
Abstraction is of the process of hiding unwanted details from the user.

31.What are virtual functions? 
A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

31.What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator? 
An internal iterator is implemented with member functions of the class that has items to step through. .An external iterator is implemented as a separate class that can be "attach" to the object that has items to step through. .An external iterator has the advantage that many difference iterators can be active simultaneously on the same object.

32.What is a scope resolution operator? 
A scope resolution operator (::), can be used to define the member functions of a class outside the class.

33.What do you mean by pure virtual functions? 
A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero.
class Shape { public: virtual void draw() = 0; };

34.What is polymorphism? Explain with an example? 
"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object.
Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for
using it to concatenate two strings.

35.What is the difference between char a[] = “string”; and char *p = “string”;? 
In the first case 6 bytes are allocated to the variable a which is fixed, where as in the second case if *p is assigned to some other value the allocate memory can change.

36.How do I initialize a pointer to a function?
This is the way to initialize a pointer to a function
void fun(int a)
{
}
void main()
{
void (*fp)(int);
fp=fun;
fp(1);
}

37.How do you link a C++ program to C functions? 
By using the extern "C" linkage specification around the C function declarations.

38.Explain the scope resolution operator? 
It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.

39.What are the differences between a C++ struct and C++ class? 
The default member and base-class access specifier are different.

40.How does throwing and catching exceptions differ from using setjmp and longjmp? 
The throw operation calls the destructors for automatic objects instantiated since entry to the try block.

41.What is a default constructor? 
Default constructor WITH arguments
class B
{
public: B
(int m = 0) : n (m)
{
}
int n;
};
int main(int argc, char *argv[])
 {
  B b;
  return 0;
}

42.What is a conversion constructor? 
A constructor that accepts one argument of a different type.

43.What is the difference between a copy constructor and an overloaded assignment operator? 
A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.

44.When should you use multiple inheritance? 
There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."

45.When is a template a better solution than a base class? 
When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of those other types are unimportant to their containment or management, and particularly when those other types are unknown (thus, the generosity) to the designer of the container or manager class.

46.What is a mutable member? 
One that can be modified by the class even when the object of the class or the member function doing the modification is const.

47.What is an explicit constructor? 
A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an implied conversion of types. It’s purpose is reserved explicitly for construction.

48.What is the Standard Template Library (STL)?
  A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification.
   A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming.

49.What is the difference between Mutex and Binary semaphore?
  semaphore is used to synchronize processes. where as mutex is used to provide synchronization between threads running in the same process.

50.In C++, what is the difference between method overloading and method overriding? 
   Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different  signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.

51.What methods can be overridden in Java? 
   In C++ terminology, all public methods in Java are virtual. Therefore, all Java methods can be overwritten in subclasses except those that are declared final, static, and private.

52.What are the defining traits of an object-oriented language? 
The defining traits of an object-oriented langauge are:
* encapsulation
* inheritance
* polymorphism

53.Assignment Operator - What is the diffrence between a "assignment operator" and a "copy constructor"?
In assignment operator, you are assigning a value to an existing object. But in copy constructor, you are creating a new object and then assigning a value to that object. For example:
complex c1,c2;
c1=c2; //this is assignment
complex c3=c2; //copy constructor

54.STL Containers - What are the types of STL containers? 
  There are 3 types of STL containers:
1. Adaptive containers like queue, stack
2. Associative containers like set, map
3. Sequence containers like vector, deque

55.What is the need for a Virtual Destructor ? 
   Destructors are declared as virtual because if do not declare it as virtual the base class destructor will be called before the derived class  destructor and that will lead to memory leak because derived class, objects will not get freed. Destructors are declared virtual so as to bind  objects to the methods at runtime so that appropriate destructor is called.

56.What is Object Oriented Programming ?
   It is a problem solving technique to develop software systems. It is a technique to think real world in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects.

57. What’s a Class ?
A class describes all the attributes of objects, as well as the methods that implement the behavior of member objects. It’s a comprehensive data type which represents a blue printof objects. It’s a template of object.

58. What’s an Object ?
It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects are members of a class. Attributes and behavior of an object are defined by the class definition.

59. What is the relation between Classes and Objects ?
   They look very much same but are not same. Class is a definition, while object is a instance of the class created. Class is a blue print while objects are actual objects existing in real world. Example we have class CAR which has attributes and methods like Speed,Brakes, Type of Car etc. Class CAR is just a prototype, now we can create real time objects which can be used to provide functionality. Example we can create a Maruti car object with 100 km speed and urgent brakes.

60.What is a Interface ?
   Interface is a contract that defines the signature of the functionality. So if a class is implementing a interface it says to the outer world, that it provides specific behavior.
Example if a class is implementing Idisposable interface that means it has a functionality to release unmanaged resources. Now external objects using this class know that it has contract by which it can dispose unused unmanaged objects.
  •  Single Class can implement multiple interfaces.
  •  If a class implements a interface then it has to provide implementation to all its methods.
Note:- In CD sample “WindowsInterFace” is provided, which has a simple interface implemented.
In sample there are two files.One has the interface definition and other class implements
the interface. Below is the source code “IInterface” is the interface and “ClsDosomething”
implements the “IInterface”. This sample just displays a simple message box.

Public Interface IInterFace
Sub DoSomething()
End Interface
Public Class ClsDoSomething
Implements IInterFace
Public Sub DoSomething() Implements
WindowsInterFace.IInterFace.DoSomething
MsgBox(“Interface implemented”)
End Sub
End Class

                                   Fig:  Interface in action

61.What is difference between abstract classes and interfaces?
Following are the differences between abstract and interfaces :-
  •  Abstract classes can have concrete methods while interfaces have no methods implemented.
  •  Interfaces do not come in inheriting chain, while abstract classes come in inheritance.
62.What is a delegate ?
      Delegate is a class that can hold a reference to a method or a function. Delegate class has a signature and it can only reference those methods whose signature is compliant with the class. Delegates are type-safe functions pointers or callbacks.
Below is a sample code which shows a example of how to implement delegates.
Public Class FrmDelegates
Inherits System.Windows.Forms.Form
Public Delegate Sub DelegateAddString()
Private Sub FrmDelegates_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub AddString()
lstDelegates.Items.Add(“Running AddString() method”)
End Sub
Private Sub cmdDelegates_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmdDelegates. Click
Dim objDelegateAddString As DelegateAddString
objDelegateAddString = AddressOf AddString
objDelegateAddString.Invoke()
End Sub
End Class
In the above there is a method called “AddString()” which adds a string to a listbox.You can also see a delegate declared as :
Public Delegate Sub DelegateAddString()
This delegate signature is compatible with the “AddString” method. When I mean compatibility that means that there return types and passing parameter types are same.
Later in command click of the button object of the Delegate is created and the method pointer is received from “AddressOf ” keyword.
Then by using the “Invoke” method the method is invoked.
                                 Figure:: Deligate in Action

63.What are events ? 
As compared to delegates events works with source and listener methodology. So listeners who are interested in receiving some events they subscribe to the source. Once this subscription is done the source raises events to its entire listener when needed. One source can have multiple listeners.
In sample given below class “ClsWithEvents” is a event source class, which has a event “EventAddString()”. Now the listeners who are interested in receiving this events they can subscribe to this event. In class “FrmWithEvents” you can see they handle clause which is associated with the “mobjClsWithEvents” objects.

Public Class ClsWithEvents
Event EventAddString(ByVal Value As String)
Public Sub AddString()
RaiseEvent EventAddString(“String added by Event”)
End Sub
End Class
Public Class FrmWithEvents
Inherits System.Windows.Forms.Form
Private WithEvents mobjClsWithEvents As New ClsWithEvents()
Private Sub FrmWithEvents_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub mobjClsWithEvents_EventAddString(ByVal Value As
String) Handles mobjClsWithEvents.EventAddString
LstData.Items.Add(Value)
End Sub
Private Sub CmdRunEvents_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CmdRunEvents.Click
mobjClsWithEvents.AddString()
End Sub
End Class
                                   Fig:  Events In Action

64.Do events have return type ?
No, events do not have return type.

65. Can event’s have access modifiers ?
Event’s are always public as they are meant to serve every one register ing to it. But you can access modifiers in events.You can have events with protected keyword which will be  accessible only to inherited classes.You can have private events only for object in that class.

66.What is shadowing ?
When two elements in a program have same name, one of them can hide and shadow the other one. So in such cases the element which shadowed  the main element is referenced.
Below is a sample code, there are two classes “ClsParent” and “ClsShadowedParent”. In “ClsParent” there is a variable “x” which is a integer.
 “ClsShadowedParent” overrides “ClsParent” and shadows the “x” variable to a string.
Note:- In Sample CD “WindowsShadowing” is folder which has the sample code. If you run the program you can have two output’s one which shows a integer and other which shows a string.
Public Class ClsParent
Public x As Integer
End Class
Public Class ClsShadowedParent
Inherits ClsParent
Public Shadows x As String
End Class
                                  Figure: Shadowing in Action

67.What is the difference between Shadowing and Overriding ?
Following are the differences between shadowing and overriding :-
  •  Overriding redefines only the implementation while shadowing redefines the whole element.
  •  In overriding derived classes can refer the parent class element by using “ME” keyword, but in shadowing you can access it by “MYBASE”.
68.What is the difference between delegate and events?
  •  Actually events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model.
  •  As delegates are function to pointers they can move across any clients. So any of the clients can add or remove events, which can be pretty confusing. But events give the extra protection by adding the layer and making it a publisher and subscriber model.
69.If we inherit a class do the private variables also get inherited ?
Yes, the variables are inherited but can not be accessed directly by the class interface.

70.What are the different accessibility levels defined in .NET?
Following are the five levels of access modifiers :-
  •  Private : Only members of class have access.
  •  Protected :-All members in current class and in derived classes can access the variables.
  • Friend (internal in C#) :- Only members in current project have access to the elements.
  •  Protected friend (protected internal in C#) :- All members in current project and all members in derived class can access the variables.
  •  Public :- All members have access in all classes and projects.
71.What are similarities between Class and structure ?
Following are the similarities between classes and structures :-
  •  Both can have constructors, methods, properties, fields, constants,enumerations, events, and event handlers.
  • Structures and classes can implement interface.
  • Both of them can have constructors with and without parameter.
  •  Both can have delegates and events.
72.What is the difference between Class and structure’s ?
Following are the key differences between them :-
  • Structure are value types and classes are reference types. So structures use stack and classes use heap.
  • Structures members can not be declared as protected, but class members can be. You can not do inheritance in structures.
  • Structures do not require constructors while classes require.
  • Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.
73.What is Dispose method in .NET ?
.NET provides “Finalize” method in which we can clean up our resources. But relying on this is not always good so the best is to implement “Idisposable” interface and implement the “Dispose” method where you can put your clean up routines.

74.What is the use of “OverRides” and “Overridable”keywords ?
Overridable is used in parent class to indicate that a method can be overridden. Overrides is used in the child class to indicate that you are overriding a method.

75.Where are all .NET Collection classes located ?
System.Collection namespace has all the collection classes available in .NET.

76. What is ArrayList ?
Array is whose size can increase and decrease dynamically. Array list can hold item of different types. As Array list can increase and decrease size dynamically you do not have to use the REDIM keyword. You can access any item in array using the INDEX value of the array position.

77. What’s a HashTable ?
You can access array using INDEX value of array, but how many times you know the real value of index. Hashtable provides way of accessing the index using a user identified KEY value, thus removing the INDEX problem.

78. What are queues and stacks ?
Queue is for first-in, first-out (FIFO) structures. Stack is for last-in, first-out (LIFO)structures.

79. What is ENUM ?
It’s used to define constants.

80.What is nested Classes ?
Nested classes are classes within classes. In sample below “ClsNested” class has a “ChildNested”
class nested inside it.
Public Class ClsNested
Public Class ChildNested
Public Sub ShowMessage()
MessageBox.Show(“Hi this is nested class”)
End Sub
End Class
End Class
This is the way we can instantiate the nested class and make the method call.
Dim pobjChildNested As New ClsNested.ChildNested()
pobjChildNested.ShowMessage()

81.In what instances you will declare a constructor to be private?
When we create a private constructor, we can not create object of the class directly from a client. So you will use private constructors when you do not want instances of the class to be created by any external client. Example UTILITY functions in project will have no instance and be used with out creating instance, as creating instances of the class would be waste of memory.

82.Can we have different access modifiers on get/set methods of a property ?
No we can not have different modifiers same property. The access modifier on a property applies to both its get and set accessors.

83.If we write a goto or a return statement in try and catch block will the finally block execute ?
The code in then finally always run even if there are statements like goto or a return statements.

84.What is Indexer ?
An indexer is a member that enables an object to be indexed in the same way as an array.

85.Can two catch blocks be executed?
No, once the proper catch section is executed the control goes finally to block. So there will not be any scenarios in which multiple catch blocks will be executed.

86.What is the difference between System.String and System.StringBuilder classes?
System.String is immutable; System.StringBuilder can have mutable string where a variety of operations can be performed.

87.Describe the accessibility modifier “protected internal”?
It is available to classes that are within the same assembly and derived from the specified base class.

88.What does the term immutable mean?
The data value may not be changed.  Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

89.What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation.  Strings are immutable, so each time a string is changed, a new instance in memory is created.

90.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.

91.What’s the advantage of using System.Text.StringBuilder over System.String? 
StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.

92.What’s a satellite assembly? 
When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

93.What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? 
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.

94.Which one is trusted and which one is untrusted?
 Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.

95.What is a pre-requisite for connection pooling? 
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

96.Does C# replace C++?
There are three options open to the Windows developer from a C++ background:
•Stick with standard C++. Don't use .NET at all.
•Use C++ with .NET. Microsoft supply a .NET C++ compiler that produces IL rather than machine code. However to make full use of the .NET environment (e.g. garbage collection), a set of extensions are required to standard C++. In .NET 1.x this extended language is called Managed Extensions for C++. In .NET 2.0 ME C++ has been completely redesigned under the stewardship of Stan Lippman, and renamed C++/CLI.
•Forget C++ and use C#.
Each of these options has merits, depending on the developer and the application. For my own part, I intend to use C# where possible, falling back to C++ only where necessary. ME C++ (soon to be C++/CLI) is very useful for interop between new .NET code and old C++ code - simply write a managed wrapper class using ME C++, then use the managed class from C#. From experience, this works well.

97.So I can pass an instance of a value type to a method that takes an object as a parameter?
Yes. For example:
class CApplication
{
public static void Main()
{
int x = 25;
string s = "fred";
DisplayMe( x );
DisplayMe( s );
}
static void DisplayMe( object o )
{
System.Console.WriteLine( "You are {0}", o );
 }
 }

This would display:
 You are 25
  You are fred

98.Does the System.Exception class have any cool features?
Yes - the feature which stands out is the StackTrace property. This provides a call stack which records where the exception was thrown from.
For example, the following code:
 using System;
 class CApp
 {
  public static void Main()
  {
  try
 {
 f();
  }
 catch( Exception e )
 {
 Console.WriteLine("System.Exception stack trace=\n{0}", e.StackTrace );
 }
 }
 static void f()
 {
 throw new Exception( "f went pear-shaped" );
  }
  }

produces this output:
System.Exception stack trace =
at CApp.f()
at CApp.Main()
Note: however, that this stack trace was produced from a debug build. A release build may optimise away some of the method calls which could mean that the call stack isn't quite what you expect.

99.How can I check the type of an object at runtime?
You can use the is keyword. For example:
using System;
class CApp
{
public static void Main()
{
string s = "fred";
long i = 10;
Console.WriteLine("{0} is {1}an integer",s,(IsInteger(s)? "" :"not") );
Console.WriteLine("{0} is {1}an integer",i,(IsInteger(i)? "" :"not") );
}
static bool IsInteger( object obj )
{
if( obj is int || obj is long )
return true;
else
return false;
}
}

produces the output:
fred is not an integer
10 is an integer.
 

100.Can I get the name of a type at runtime?
Yes, use the GetType method of the object class (which all types inherit from). For example:
using System;
class CTest
{
class CApp
{
public static void Main()
{
long i = 10;
CTest ctest = new CTest();
DisplayTypeInfo( ctest );
DisplayTypeInfo( i );
}
static void DisplayTypeInfo( object obj )
{
Console.WriteLine("Type name={0}, full type name={1}", obj.GetType(), 
obj.GetType().FullName );
}
}
}
produces the following output:
Type name = CTest, full type name = CTest
Type name = Int64, full type name = System.Int64