(This posting is a continuation of
this blog posting.)
If you want to implement this the OOP way, here you have the subclass code (which I'll use myself).
using System.Collections.Generic;
// Remember to set this to your proper namespace (or use a using statement in
// the class with the LINQ projection)
namespace MyNamespace
{
/// <summary>
/// Extension methods for the Dictionary generic class.
/// </summary>
public class ImprovedDictionary<T1,T2>: Dictionary<T1,T2>
{
/// <summary>
/// Add a key/value pair to the dictionary and return the dictionary reference.
/// </summary>
/// <param name="key">the key</param>
/// <param name="value">the value</param>
/// <returns>the dictionary</returns>
public ImprovedDictionary<T1, T2> AddWithReturn(T1 key, T2 value)
{
this[key] = value;
return this;
}
}
}