/// <summary> /// Copies the entire <see cref="Map{TKey1, TKey2}"/> to a compatible one-dimensional array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from <see cref="Map{TKey1, TKey2}"/>. The <see cref="Array"/> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param> /// <exception cref="ArgumentNullException">When <paramref name="array"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">When <paramref name="arrayIndex"/> is smaller than zero or larger than the length of <paramref name="array"/>.</exception> /// <exception cref="ArgumentException">When <paramref name="array"/> is too small.</exception> public void CopyTo(KeyPair <TKey1, TKey2>[] array, int arrayIndex) { if (array == null) { throw ExceptionHelper.ArgumentNull(nameof(array)); } if (arrayIndex < 0 || arrayIndex > array.Length) { throw ExceptionHelper.ArgumentOutOfRange(nameof(arrayIndex)); } if (array.Length - arrayIndex < dic.Count) { throw ExceptionHelper.ArrayTooSmall(); } foreach (var item in this) { array[arrayIndex++] = item; } }
/// <summary> /// Copies the entire <see cref="Map{TKey1, TKey2}"/> to a compatible one-dimensional array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from <see cref="Map{TKey1, TKey2}"/>. The <see cref="Array"/> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param> /// <exception cref="ArgumentNullException">When <paramref name="array"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">When <paramref name="arrayIndex"/> is smaller than zero or larger than the length of <paramref name="array"/>.</exception> /// <exception cref="ArgumentException">When <paramref name="array"/> is too small.</exception> public void CopyTo(KeyPair <TKey1, TKey2>[] array, int arrayIndex) { if (array == null) { throw ExceptionHelper.ArgumentNull(nameof(array)); } if (arrayIndex < 0 || arrayIndex > array.Length) { throw ExceptionHelper.ArgumentOutOfRange(nameof(arrayIndex)); } if (array.Length - arrayIndex < dic.Count) { throw ExceptionHelper.ArrayTooSmall(); } foreach (var pair in dic) { array[arrayIndex] = new KeyPair <TKey1, TKey2>(pair.Key, pair.Value); arrayIndex++; } }
/// <summary> /// Copies the entire <see cref="Collection{T}"/> to a compatible one-dimensional <see cref="Array"/>, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the elements copied from <see cref="Collection{T}"/>. The <see cref="Array"/> must have zero-based indexing.</param> /// <param name="arrayIndex">The zero-based index in array at which copying begins.</param> public void CopyTo(TElement[] array, int arrayIndex) { if (array == null) { throw ExceptionHelper.ArgumentNull(nameof(array)); } if (arrayIndex < 0) { throw ExceptionHelper.ArgumentOutOfRange(nameof(arrayIndex)); } if (arrayIndex > array.Length) { throw ExceptionHelper.ArgumentOutOfRange(nameof(arrayIndex)); } if (array.Length - arrayIndex < collection.Count) { throw ExceptionHelper.ArrayTooSmall(); } collection.CopyTo(array, arrayIndex); }