andrew4582

CollectionExtensions

Oct 27th, 2012
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.  /// <summary>
  2.     /// Class that provides extension methods to Collection
  3.     /// </summary>
  4.     public static class CollectionExtensions
  5.     {
  6.         /// <summary>
  7.         /// Add a range of items to a collection.
  8.         /// </summary>
  9.         /// <typeparam name="T">Type of objects within the collection.</typeparam>
  10.         /// <param name="collection">The collection to add items to.</param>
  11.         /// <param name="items">The items to add to the collection.</param>
  12.         /// <returns>The collection.</returns>
  13.         /// <exception cref="System.ArgumentNullException">An <see cref="System.ArgumentNullException"/> is thrown if <paramref name="collection"/> or <paramref name="items"/> is <see langword="null"/>.</exception>
  14.         public static Collection<T> AddRange<T>(this Collection<T> collection, IEnumerable<T> items)
  15.         {
  16.             if (collection == null) throw new System.ArgumentNullException("collection");
  17.             if (items == null) throw new System.ArgumentNullException("items");
  18.  
  19.             foreach (var each in items)
  20.             {
  21.                 collection.Add(each);
  22.             }
  23.  
  24.             return collection;
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment