public static EnumerateElementAtIndex ( IEnumerable enumerable, int index ) : object | ||
enumerable | IEnumerable |
/// The |
index | int | /// The index of the element in the enumeration to return. /// |
return | object |
public void EnumerateElementAtNegativeIndexViaIEnumerable() { string expected = "Mmm..."; IList list = new string[] { "Aw!", "Man!", expected }; Assert.Throws <ArgumentOutOfRangeException>(() => ObjectUtils.EnumerateElementAtIndex(list, -10)); }
public void EnumerateElementAtNegativeIndexViaIEnumerable() { string expected = "Mmm..."; IList list = new string[] { "Aw!", "Man!", expected }; object actual = ObjectUtils.EnumerateElementAtIndex(list, -10); Assert.AreEqual(expected, actual); }
public void EnumerateElementAtOutOfRangeIndex() { string expected = "Mmm..."; IList list = new string[] { "Aw!", "Man!", expected }; IEnumerator enumerator = list.GetEnumerator(); Assert.Throws <ArgumentOutOfRangeException>(() => ObjectUtils.EnumerateElementAtIndex(enumerator, 12)); }
public void EnumerateElementAtNegativeIndex() { string expected = "Mmm..."; IList list = new string[] { "Aw!", "Man!", expected }; IEnumerator enumerator = list.GetEnumerator(); object actual = ObjectUtils.EnumerateElementAtIndex(enumerator, -10); Assert.AreEqual(expected, actual); }
/// <summary> /// Returns the element at the specified index using the supplied /// <paramref name="enumerable"/>. /// </summary> /// <param name="enumerable"> /// The <see cref="System.Collections.IEnumerable"/> to use to enumerate /// elements until the supplied <paramref name="index"/> is reached. /// </param> /// <param name="index"> /// The index of the element in the enumeration to return. /// </param> /// <returns> /// The element at the specified index using the supplied /// <paramref name="enumerable"/>. /// </returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// If the supplied <paramref name="index"/> was less than zero, or the /// supplied <paramref name="enumerable"/> did not contain enough elements /// to be able to reach the supplied <paramref name="index"/>. /// </exception> /// <exception cref="System.ArgumentNullException"> /// If the supplied <paramref name="enumerable"/> is <see langword="null"/>. /// </exception> public static object EnumerateElementAtIndex(IEnumerable enumerable, int index) { AssertUtils.ArgumentNotNull(enumerable, "enumerable"); return(ObjectUtils.EnumerateElementAtIndex(enumerable.GetEnumerator(), index)); }
/// <summary> /// Returns the first element in the supplied <paramref name="enumerator"/>. /// </summary> /// <param name="enumerator"> /// The <see cref="System.Collections.IEnumerator"/> to use to enumerate /// elements. /// </param> /// <returns> /// The first element in the supplied <paramref name="enumerator"/>. /// </returns> /// <exception cref="System.IndexOutOfRangeException"> /// If the supplied <paramref name="enumerator"/> did not have any elements. /// </exception> public static object EnumerateFirstElement(IEnumerator enumerator) { return(ObjectUtils.EnumerateElementAtIndex(enumerator, 0)); }