1
0

EnumerableGrouping.cs 949 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace System.Linq
  8. {
  9. class EnumerableGrouping<TKey, TElement> : IGrouping<TKey, TElement>
  10. {
  11. List<TElement> elements = new List<TElement>();
  12. public EnumerableGrouping(TKey key)
  13. {
  14. Key = key;
  15. }
  16. public void Add(TElement element)
  17. {
  18. elements.Add(element);
  19. }
  20. public TKey Key { get; private set; }
  21. public IEnumerator<TElement> GetEnumerator()
  22. {
  23. return elements.GetEnumerator();
  24. }
  25. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  26. {
  27. return this.GetEnumerator();
  28. }
  29. }
  30. }