Adds an enumerable of entries to the specified dictionary. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

Adds an enumerable of entries to the specified dictionary.

Demo Code


using System.Diagnostics;
using System.Collections.Generic;
using System;/*www.  ja va2 s .c  o m*/

public class Main{
        /// <summary>
      /// Adds an enumerable of entries to the specified dictionary.
      /// </summary>
      /// <param name="dictionary">A <see cref="Dictionary{TKey,TValue}"/>.</param>
      /// <param name="pairs">An enumerable of <see cref="KeyValuePair{TKey,TValue}"/> to add.</param>
      /// <exception cref="ArgumentNullException">Thrown when <paramref name="dictionary"/> is null.</exception>
      /// <exception cref="ArgumentNullException">Thrown when <paramref name="pairs"/> is null.</exception>
      public static void AddMany<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, IEnumerable<KeyValuePair<TKey, TValue>> pairs)
      {
         dictionary.ThrowIfNull("dictionary");
         pairs.ThrowIfNull("pairs");

         foreach (KeyValuePair<TKey, TValue> pair in pairs)
         {
            dictionary.Add(pair.Key, pair.Value);
         }
      }
}

Related Tutorials