I’ve been doing c# for a long time, and have never come across an easy way to just new up a hash.
I’ve recently become acquainted with the ruby syntax of hashes and wonder, does anyone know of a simple way to declare a hash as a literal, without doing all the add calls.
{ 'whatever' => {i => 1}; 'and then something else' => {j => 2}};
If you’re using C# 3.0 (.NET 3.5) then you can use collection initializers. They’re not quite as terse as in Ruby but still an improvement.
This example is based on the MSDN Example