Per Lundberg

Random thoughts from a BizTalk developer
posts - 10, comments - 12, trackbacks - 0

My Links

News

Archives

Post Categories

Instantiating a Dictionary from a LINQ projection, part 2

(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;
        }
    }
}
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Wednesday, April 29, 2009 9:43 AM | Filed Under [ .NET C# LINQ ]

Feedback

Gravatar

# re: Instantiating a Dictionary from a LINQ projection, part 2

Please see the original posting for some important comments regarding this. There is a problem with using the class here, if you try to use it from within a LINQ projection.

The solution is discussed here: http://geekswithblogs.net/plundberg/archive/2009/04/29/instantiating-a-dictionary-from-a-linq-projection.aspx#feedback
5/6/2009 9:41 AM | Per Lundberg
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: