Set - 4

Question 21 :

Contrast the use of an abstract base class against an interface?

Answer :

In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes

Whether to Choose VB.NET/C#.
Both the languages are using same classes and namespaces. Once it compile and generates MSIL, there is no meaning of which language it was written. If you are Java/C++ programmer better to choose C# for same coding style otherwise you can choose

Question 22 :

How would one do a deep copy in .NET?

Answer :

System.Array.CopyTo() - Deep copies an Array

How would one do a deep copy in .NET?
The First Approach.
1.Create a new instance.
2.Copy the properties from source instance to newly created instance.
[Use reflection if you want to write a common method to achive this]

The Second Approach.
1. Serialize the object and deserialize the output.
: Use binary serialization if you want private variables to be copied.
: Use xml Serialization if you dont want private variable to be copied.

Question 23 :

What is boxing?

Answer :

Boxing is an implicit conversion of a value type to the type object
int i = 123; // A value type
Object box = i // Boxing
Unboxing is an explicit conversion from the type object to a value type
int i = 123; // A value type object box = i; // Boxing
int j = (int)box; // Unboxing

Question 24 :

Is string a value type or a reference type?

Answer :

String is Reference Type.
Value type - bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short,strut, uint, ulong, ushort
Value types are stored in the Stack
Reference type - class, delegate, interface, object, string
Reference types are stored in the Heap

Yes String is reference type. C# gives two types of variable reference and value type. string and object are reference type.

Question 25 :

How does the lifecycle of Windows services differ from Standard EXE?

Answer :

Windows services lifecycle is managed by "Service Control Manager" which is responsible for starting and stopping the service and the applications do not have a user interface or produce any visual output, but "Standard executable" does not require Control Manager and is directly related to the visual output