Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<AttendeeInfo> attendees = new List<AttendeeInfo>();
- foreach ...
- // Error: "There are too many target users in the email address array"
- // for more than 100 attendees. So take the first 100 attendees only.
- if(attendees.Count > 100) attendees = attendees.GetRange(0,100);
- // or
- if(attendees.Count > 100) attendees = attendees.Take(100).ToList();
- var list = Enumerable.Range(0, 1000).ToList();
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- for(var i=0; i<1000000; i++)
- {
- var c = list.GetRange(0, 100);
- }
- Console.WriteLine(stopwatch.Elapsed);
- stopwatch.Restart();
- for (var i = 0; i < 1000000; i++)
- {
- var c = list.Take(100).ToList();
- }
- Console.WriteLine(stopwatch.Elapsed);
- public List<T> GetRange(int index, int count)
- {
- if (index < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if (count < 0)
- {
- ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum);
- }
- if ((this._size - index) < count)
- {
- ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen);
- }
- List<T> list = new List<T>(count);
- Array.Copy(this._items, index, list._items, 0, count); // Implemented natively
- list._size = count;
- return list;
- }
- public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count)
- {
- if (source == null)
- {
- throw Error.ArgumentNull("source");
- }
- return TakeIterator<TSource>(source, count);
- }
- private static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count)
- {
- if (count > 0)
- {
- foreach (TSource iteratorVariable0 in source)
- {
- yield return iteratorVariable0;
- if (--count == 0)
- {
- break;
- }
- }
- }
- }
- public static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
- {
- if (source == null)
- {
- throw Error.ArgumentNull("source");
- }
- return new List<TSource>(source);
- }
- public List(IEnumerable<T> collection)
- {
- if (collection == null)
- {
- ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection);
- }
- ICollection<T> is2 = collection as ICollection<T>;
- if (is2 != null)
- {
- int count = is2.Count;
- if (count == 0)
- {
- this._items = List<T>._emptyArray;
- }
- else
- {
- this._items = new T[count];
- is2.CopyTo(this._items, 0);
- this._size = count;
- }
- }
- else
- {
- this._size = 0;
- this._items = List<T>._emptyArray;
- using (IEnumerator<T> enumerator = collection.GetEnumerator())
- {
- while (enumerator.MoveNext())
- {
- this.Add(enumerator.Current);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment