Saturday, May 12, 2012

Difference between Dictionary and Hashtable

Dictionary
System.Collections.Generic.Dictionary<object,object>

Dictionary<TKey,TValue> is a generic type, allowing:
 
  • static typing (and compile-time verification)
  • use without boxing
If you are .NET 2.0 or above, you should prefer Dictionary<TKey,TValue> (and the other generic collections)

Hashtable
System.Collections.Hashtable

Hashtable is of collection type.
A subtle but important difference is that Hashtable supports multiple reader threads with a single writer thread, while Dictionary offers no thread safety.
If you need thread safety with a generic dictionary, you must implement your own synchronization or (in .NET 4.0) use ConcurrentDictionary<TKey, TValue>.

Best of Luck.

Find the largest contingent array in an array of integers.

A common interview question on Algorithms is to find the set of elements from an Array which has maximum sum.
In other words it is “Find the largest contingent array in an array of integers.”.

You can achieve it in only 3 lines of logical code/algorithm.
I am here pasting the C# solution code for the same problem.


"result" array will contain the Contingent Array and "sum" will contain Max sum from the array.

Hope this will help you a lot.
Best of luck.