Почувствуйте разницу:
// System.Linq.Enumerable
public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index)
{
if (source == null)
{
throw Error.ArgumentNull("source");
}
IList<TSource> list = source as IList<TSource>;
if (list != null)
{
return list[index];
}
if (index < 0)
{
throw Error.ArgumentOutOfRange("index");
}
TSource current;
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (index == 0)
{
current = enumerator.Current;
return current;
}
index--;
}
throw Error.ArgumentOutOfRange("index");
}
return current;
}
----------------------------------------------------------------------------
// System.Collections.Generic.List<T>
public T this[int index]
{
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
get
{
if (index >= this._size)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
return this._items[index];
}
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
set
{
if (index >= this._size)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
this._items[index] = value;
this._version++;
}
}
Другие языки программирования и технологии
Подскажи по-быстрому, есть ли разница в юзании [ ] и ElementAt() у List<> в C#? Если есть, то какая?
у листа тоже индексатор есть как бы)
Похожие вопросы
- помогите составить таблицы истиности -А -> (B + C); (A B) * C; -A + -B + C; - (A + B) * C ; A * B _+ C; A B
- Помогите, как сделать такой символ? < >
- Какие знаки принято использовать в блок-схемах? Обязательно ненормальные := и даже <>?
- Что значит "->" в C++?
- что значит это this -> в c++
- Подскажите, как быстрее всего освоить Word? (Для верстки книги в ворде)
- Подскажите как переделать что б оно считало суму отрицательньіх елементво основной матрицьі, а не отсортированой? C++
- <<<<<<<<<<<<html>>>>>>>>>>>>...
- Mozila: HTML+CSS <col> не работает. В чем проблема?
- Вопрос C++. #include <iostream> using namespace std; int main() { int h; cout << "Vvedite chislo" <