CopyToExtensions.cs 1.2 KB

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