Set - 10

Question 1 :

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

Answer :

The first one performs a deep copy of the array, the second one is shallow. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.


Question 2 :

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

Answer :

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


Question 3 :

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

Answer :

HashTable.


Question 4 :

What class is underneath the SortedList class?

Answer :

A sorted HashTable.


Question 5 :

Will the finally block get executed if an exception has not occurred?

Answer :

Yes.


Question 6 :

What's the C# syntax to catch any possible exception?

Answer :

A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.


Question 7 :

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

Answer :

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


Question 8 :

Explain the three services model commonly know as a three-tier application?

Answer :

Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).


Question 9 :

Why does DllImport not work for me?

Answer :

All methods marked with the DllImport attribute must be marked as public static extern.


Question 10 :

What is a delegate?

Answer :

A delegate object encapsulates a reference to a method. In C++ they were referred to as function pointers.


Question 11 :

What is the difference between an interface and abstract class?

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. 


Question 12 :

What is an abstract class?

Answer :

A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it is a blueprint for a class without any implementation. 
_break


Question 13 :

Does C# support multiple-inheritance?

Answer :

No.


Question 14 :

Who is a protected class-level variable available to?

Answer :

It is available to any sub-class (a class inheriting this class).


Question 15 :

Can you store multiple data types in System.Array? 

Answer :

No.


Question 16 :

What's the top .NET class that everything is derived from?

Answer :

System.Object.

 


Question 17 :

What does the term immutable mean?

Answer :

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.


Question 18 :

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

Answer :

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


Question 19 :

What's the advantage of using System.Text.StringBuilder over System.String?

Answer :

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. 


Question 20 :

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

Answer :

Explanation :

The first one performs a deep copy of the array, the second one is shallow. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.