CopyToExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. using System.Collections.Generic;
  2. namespace MediaBrowser.Common.Extensions
  3. {
  4. /// <summary>
  5. /// Provides <c>CopyTo</c> extensions methods for <see cref="IReadOnlyList{T}" />.
  6. /// </summary>
  7. public static class CopyToExtensions
  8. {
  9. /// <summary>
  10. /// Copies all the elements of the current collection to the specified list
  11. /// starting at the specified destination array index. The index is specified as a 32-bit integer.
  12. /// </summary>
  13. /// <param name="source">The current collection that is the source of the elements.</param>
  14. /// <param name="destination">The list that is the destination of the elements copied from the current collection.</param>
  15. /// <param name="index">A 32-bit integer that represents the index in <c>destination</c> at which copying begins.</param>
  16. /// <typeparam name="T">The type of the array.</typeparam>
  17. public static void CopyTo<T>(this IReadOnlyList<T> source, IList<T> destination, int index = 0)
  18. {
  19. for (int i = 0; i < source.Count; i++)
  20. {
  21. destination[index + i] = source[i];
  22. }
  23. }
  24. }
  25. }