mscorlib(4.0.0.0) API with additions
Enumerable.cs
1 using System.Collections;
3 using System.Threading;
4 
5 namespace System.Linq
6 {
8  [global::__DynamicallyInvokable]
9  public static class Enumerable
10  {
11  private abstract class Iterator<TSource> : IEnumerable<TSource>, IEnumerable, IEnumerator<TSource>, IDisposable, IEnumerator
12  {
13  private int threadId;
14 
15  internal int state;
16 
17  internal TSource current;
18 
19  public TSource Current => current;
20 
21  object IEnumerator.Current
22  {
23  get
24  {
25  return Current;
26  }
27  }
28 
29  public Iterator()
30  {
32  }
33 
34  public abstract Iterator<TSource> Clone();
35 
36  public virtual void Dispose()
37  {
38  current = default(TSource);
39  state = -1;
40  }
41 
42  public IEnumerator<TSource> GetEnumerator()
43  {
44  if (threadId == Thread.CurrentThread.ManagedThreadId && state == 0)
45  {
46  state = 1;
47  return this;
48  }
49  Iterator<TSource> iterator = Clone();
50  iterator.state = 1;
51  return iterator;
52  }
53 
54  public abstract bool MoveNext();
55 
56  public abstract IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector);
57 
58  public abstract IEnumerable<TSource> Where(Func<TSource, bool> predicate);
59 
61  {
62  return GetEnumerator();
63  }
64 
65  void IEnumerator.Reset()
66  {
67  throw new NotImplementedException();
68  }
69  }
70 
71  private class WhereEnumerableIterator<TSource> : Iterator<TSource>
72  {
73  private IEnumerable<TSource> source;
74 
75  private Func<TSource, bool> predicate;
76 
77  private IEnumerator<TSource> enumerator;
78 
79  public WhereEnumerableIterator(IEnumerable<TSource> source, Func<TSource, bool> predicate)
80  {
81  this.source = source;
82  this.predicate = predicate;
83  }
84 
85  public override Iterator<TSource> Clone()
86  {
87  return new WhereEnumerableIterator<TSource>(source, predicate);
88  }
89 
90  public override void Dispose()
91  {
92  if (enumerator != null)
93  {
94  enumerator.Dispose();
95  }
96  enumerator = null;
97  base.Dispose();
98  }
99 
100  public override bool MoveNext()
101  {
102  int state = base.state;
103  if (state != 1)
104  {
105  if (state != 2)
106  {
107  goto IL_0061;
108  }
109  }
110  else
111  {
112  enumerator = source.GetEnumerator();
113  base.state = 2;
114  }
115  while (enumerator.MoveNext())
116  {
117  TSource current = enumerator.Current;
118  if (predicate(current))
119  {
120  base.current = current;
121  return true;
122  }
123  }
124  Dispose();
125  goto IL_0061;
126  IL_0061:
127  return false;
128  }
129 
130  public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector)
131  {
132  return new WhereSelectEnumerableIterator<TSource, TResult>(source, predicate, selector);
133  }
134 
135  public override IEnumerable<TSource> Where(Func<TSource, bool> predicate)
136  {
137  return new WhereEnumerableIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
138  }
139  }
140 
141  private class WhereArrayIterator<TSource> : Iterator<TSource>
142  {
143  private TSource[] source;
144 
145  private Func<TSource, bool> predicate;
146 
147  private int index;
148 
149  public WhereArrayIterator(TSource[] source, Func<TSource, bool> predicate)
150  {
151  this.source = source;
152  this.predicate = predicate;
153  }
154 
155  public override Iterator<TSource> Clone()
156  {
157  return new WhereArrayIterator<TSource>(source, predicate);
158  }
159 
160  public override bool MoveNext()
161  {
162  if (state == 1)
163  {
164  while (index < source.Length)
165  {
166  TSource val = source[index];
167  index++;
168  if (predicate(val))
169  {
170  current = val;
171  return true;
172  }
173  }
174  Dispose();
175  }
176  return false;
177  }
178 
179  public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector)
180  {
181  return new WhereSelectArrayIterator<TSource, TResult>(source, predicate, selector);
182  }
183 
184  public override IEnumerable<TSource> Where(Func<TSource, bool> predicate)
185  {
186  return new WhereArrayIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
187  }
188  }
189 
190  private class WhereListIterator<TSource> : Iterator<TSource>
191  {
192  private List<TSource> source;
193 
194  private Func<TSource, bool> predicate;
195 
196  private List<TSource>.Enumerator enumerator;
197 
198  public WhereListIterator(List<TSource> source, Func<TSource, bool> predicate)
199  {
200  this.source = source;
201  this.predicate = predicate;
202  }
203 
204  public override Iterator<TSource> Clone()
205  {
206  return new WhereListIterator<TSource>(source, predicate);
207  }
208 
209  public override bool MoveNext()
210  {
211  int state = base.state;
212  if (state != 1)
213  {
214  if (state != 2)
215  {
216  goto IL_0061;
217  }
218  }
219  else
220  {
221  enumerator = source.GetEnumerator();
222  base.state = 2;
223  }
224  while (enumerator.MoveNext())
225  {
226  TSource current = enumerator.Current;
227  if (predicate(current))
228  {
229  base.current = current;
230  return true;
231  }
232  }
233  Dispose();
234  goto IL_0061;
235  IL_0061:
236  return false;
237  }
238 
239  public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector)
240  {
241  return new WhereSelectListIterator<TSource, TResult>(source, predicate, selector);
242  }
243 
244  public override IEnumerable<TSource> Where(Func<TSource, bool> predicate)
245  {
246  return new WhereListIterator<TSource>(source, CombinePredicates(this.predicate, predicate));
247  }
248  }
249 
250  private class SelectEnumerableIterator<TSource, TResult> : Iterator<TResult>, IIListProvider<TResult>, IEnumerable<TResult>, IEnumerable
251  {
252  private readonly IEnumerable<TSource> _source;
253 
254  private readonly Func<TSource, TResult> _selector;
255 
256  private IEnumerator<TSource> _enumerator;
257 
258  public SelectEnumerableIterator(IEnumerable<TSource> source, Func<TSource, TResult> selector)
259  {
260  _source = source;
261  _selector = selector;
262  }
263 
264  public override Iterator<TResult> Clone()
265  {
266  return new SelectEnumerableIterator<TSource, TResult>(_source, _selector);
267  }
268 
269  public override void Dispose()
270  {
271  if (_enumerator != null)
272  {
273  _enumerator.Dispose();
274  _enumerator = null;
275  }
276  base.Dispose();
277  }
278 
279  public override bool MoveNext()
280  {
281  int state = base.state;
282  if (state != 1)
283  {
284  if (state != 2)
285  {
286  goto IL_005a;
287  }
288  }
289  else
290  {
291  _enumerator = _source.GetEnumerator();
292  base.state = 2;
293  }
294  if (_enumerator.MoveNext())
295  {
296  current = _selector(_enumerator.Current);
297  return true;
298  }
299  Dispose();
300  goto IL_005a;
301  IL_005a:
302  return false;
303  }
304 
305  public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector)
306  {
307  return new SelectEnumerableIterator<TSource, TResult2>(_source, CombineSelectors(_selector, selector));
308  }
309 
310  public override IEnumerable<TResult> Where(Func<TResult, bool> predicate)
311  {
312  return new WhereEnumerableIterator<TResult>(this, predicate);
313  }
314 
315  public TResult[] ToArray()
316  {
317  LargeArrayBuilder<TResult> largeArrayBuilder = new LargeArrayBuilder<TResult>(initialize: true);
318  foreach (TSource item in _source)
319  {
320  largeArrayBuilder.Add(_selector(item));
321  }
322  return largeArrayBuilder.ToArray();
323  }
324 
325  public List<TResult> ToList()
326  {
327  List<TResult> list = new List<TResult>();
328  foreach (TSource item in _source)
329  {
330  list.Add(_selector(item));
331  }
332  return list;
333  }
334 
335  public int GetCount(bool onlyIfCheap)
336  {
337  if (onlyIfCheap)
338  {
339  return -1;
340  }
341  int num = 0;
342  foreach (TSource item in _source)
343  {
344  _selector(item);
345  num = checked(num + 1);
346  }
347  return num;
348  }
349  }
350 
351  private class WhereSelectEnumerableIterator<TSource, TResult> : Iterator<TResult>
352  {
353  private IEnumerable<TSource> source;
354 
355  private Func<TSource, bool> predicate;
356 
357  private Func<TSource, TResult> selector;
358 
359  private IEnumerator<TSource> enumerator;
360 
361  public WhereSelectEnumerableIterator(IEnumerable<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector)
362  {
363  this.source = source;
364  this.predicate = predicate;
365  this.selector = selector;
366  }
367 
368  public override Iterator<TResult> Clone()
369  {
370  return new WhereSelectEnumerableIterator<TSource, TResult>(source, predicate, selector);
371  }
372 
373  public override void Dispose()
374  {
375  if (enumerator != null)
376  {
377  enumerator.Dispose();
378  }
379  enumerator = null;
380  base.Dispose();
381  }
382 
383  public override bool MoveNext()
384  {
385  int state = base.state;
386  if (state != 1)
387  {
388  if (state != 2)
389  {
390  goto IL_0074;
391  }
392  }
393  else
394  {
395  enumerator = source.GetEnumerator();
396  base.state = 2;
397  }
398  while (enumerator.MoveNext())
399  {
400  TSource current = enumerator.Current;
401  if (predicate == null || predicate(current))
402  {
403  base.current = selector(current);
404  return true;
405  }
406  }
407  Dispose();
408  goto IL_0074;
409  IL_0074:
410  return false;
411  }
412 
413  public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector)
414  {
415  return new WhereSelectEnumerableIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
416  }
417 
418  public override IEnumerable<TResult> Where(Func<TResult, bool> predicate)
419  {
420  return new WhereEnumerableIterator<TResult>(this, predicate);
421  }
422  }
423 
424  private class WhereSelectArrayIterator<TSource, TResult> : Iterator<TResult>
425  {
426  private TSource[] source;
427 
428  private Func<TSource, bool> predicate;
429 
430  private Func<TSource, TResult> selector;
431 
432  private int index;
433 
434  public WhereSelectArrayIterator(TSource[] source, Func<TSource, bool> predicate, Func<TSource, TResult> selector)
435  {
436  this.source = source;
437  this.predicate = predicate;
438  this.selector = selector;
439  }
440 
441  public override Iterator<TResult> Clone()
442  {
443  return new WhereSelectArrayIterator<TSource, TResult>(source, predicate, selector);
444  }
445 
446  public override bool MoveNext()
447  {
448  if (state == 1)
449  {
450  while (index < source.Length)
451  {
452  TSource arg = source[index];
453  index++;
454  if (predicate == null || predicate(arg))
455  {
456  current = selector(arg);
457  return true;
458  }
459  }
460  Dispose();
461  }
462  return false;
463  }
464 
465  public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector)
466  {
467  return new WhereSelectArrayIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
468  }
469 
470  public override IEnumerable<TResult> Where(Func<TResult, bool> predicate)
471  {
472  return new WhereEnumerableIterator<TResult>(this, predicate);
473  }
474  }
475 
476  private class WhereSelectListIterator<TSource, TResult> : Iterator<TResult>
477  {
478  private List<TSource> source;
479 
480  private Func<TSource, bool> predicate;
481 
482  private Func<TSource, TResult> selector;
483 
484  private List<TSource>.Enumerator enumerator;
485 
486  public WhereSelectListIterator(List<TSource> source, Func<TSource, bool> predicate, Func<TSource, TResult> selector)
487  {
488  this.source = source;
489  this.predicate = predicate;
490  this.selector = selector;
491  }
492 
493  public override Iterator<TResult> Clone()
494  {
495  return new WhereSelectListIterator<TSource, TResult>(source, predicate, selector);
496  }
497 
498  public override bool MoveNext()
499  {
500  int state = base.state;
501  if (state != 1)
502  {
503  if (state != 2)
504  {
505  goto IL_0074;
506  }
507  }
508  else
509  {
510  enumerator = source.GetEnumerator();
511  base.state = 2;
512  }
513  while (enumerator.MoveNext())
514  {
515  TSource current = enumerator.Current;
516  if (predicate == null || predicate(current))
517  {
518  base.current = selector(current);
519  return true;
520  }
521  }
522  Dispose();
523  goto IL_0074;
524  IL_0074:
525  return false;
526  }
527 
528  public override IEnumerable<TResult2> Select<TResult2>(Func<TResult, TResult2> selector)
529  {
530  return new WhereSelectListIterator<TSource, TResult2>(source, predicate, CombineSelectors(this.selector, selector));
531  }
532 
533  public override IEnumerable<TResult> Where(Func<TResult, bool> predicate)
534  {
535  return new WhereEnumerableIterator<TResult>(this, predicate);
536  }
537  }
538 
539  private abstract class AppendPrependIterator<TSource> : Iterator<TSource>, IIListProvider<TSource>, IEnumerable<TSource>, IEnumerable
540  {
541  protected readonly IEnumerable<TSource> _source;
542 
543  protected IEnumerator<TSource> enumerator;
544 
545  protected AppendPrependIterator(IEnumerable<TSource> source)
546  {
547  _source = source;
548  }
549 
550  protected void GetSourceEnumerator()
551  {
552  enumerator = _source.GetEnumerator();
553  }
554 
555  public abstract AppendPrependIterator<TSource> Append(TSource item);
556 
557  public abstract AppendPrependIterator<TSource> Prepend(TSource item);
558 
559  protected bool LoadFromEnumerator()
560  {
561  if (enumerator.MoveNext())
562  {
563  current = enumerator.Current;
564  return true;
565  }
566  Dispose();
567  return false;
568  }
569 
570  public override void Dispose()
571  {
572  if (enumerator != null)
573  {
574  enumerator.Dispose();
575  enumerator = null;
576  }
577  base.Dispose();
578  }
579 
580  public override IEnumerable<TResult> Select<TResult>(Func<TSource, TResult> selector)
581  {
582  return new SelectEnumerableIterator<TSource, TResult>(this, selector);
583  }
584 
585  public override IEnumerable<TSource> Where(Func<TSource, bool> predicate)
586  {
587  return new WhereEnumerableIterator<TSource>(this, predicate);
588  }
589 
590  public abstract TSource[] ToArray();
591 
592  public abstract List<TSource> ToList();
593 
594  public abstract int GetCount(bool onlyIfCheap);
595  }
596 
597  private class AppendPrepend1Iterator<TSource> : AppendPrependIterator<TSource>
598  {
599  private readonly TSource _item;
600 
601  private readonly bool _appending;
602 
603  public AppendPrepend1Iterator(IEnumerable<TSource> source, TSource item, bool appending)
604  : base(source)
605  {
606  _item = item;
607  _appending = appending;
608  }
609 
610  public override Iterator<TSource> Clone()
611  {
612  return new AppendPrepend1Iterator<TSource>(_source, _item, _appending);
613  }
614 
615  public override bool MoveNext()
616  {
617  switch (state)
618  {
619  case 1:
620  state = 2;
621  if (!_appending)
622  {
623  current = _item;
624  return true;
625  }
626  goto case 2;
627  case 2:
628  GetSourceEnumerator();
629  state = 3;
630  goto case 3;
631  case 3:
632  if (LoadFromEnumerator())
633  {
634  return true;
635  }
636  if (_appending)
637  {
638  current = _item;
639  return true;
640  }
641  break;
642  }
643  Dispose();
644  return false;
645  }
646 
647  public override AppendPrependIterator<TSource> Append(TSource item)
648  {
649  if (_appending)
650  {
651  return new AppendPrependN<TSource>(_source, null, new SingleLinkedNode<TSource>(_item).Add(item), 0, 2);
652  }
653  return new AppendPrependN<TSource>(_source, new SingleLinkedNode<TSource>(_item), new SingleLinkedNode<TSource>(item), 1, 1);
654  }
655 
656  public override AppendPrependIterator<TSource> Prepend(TSource item)
657  {
658  if (_appending)
659  {
660  return new AppendPrependN<TSource>(_source, new SingleLinkedNode<TSource>(item), new SingleLinkedNode<TSource>(_item), 1, 1);
661  }
662  return new AppendPrependN<TSource>(_source, new SingleLinkedNode<TSource>(_item).Add(item), null, 2, 0);
663  }
664 
665  private TSource[] LazyToArray()
666  {
667  LargeArrayBuilder<TSource> largeArrayBuilder = new LargeArrayBuilder<TSource>(initialize: true);
668  if (!_appending)
669  {
670  largeArrayBuilder.SlowAdd(_item);
671  }
672  largeArrayBuilder.AddRange(_source);
673  if (_appending)
674  {
675  largeArrayBuilder.SlowAdd(_item);
676  }
677  return largeArrayBuilder.ToArray();
678  }
679 
680  public override TSource[] ToArray()
681  {
682  int count = GetCount(onlyIfCheap: true);
683  if (count == -1)
684  {
685  return LazyToArray();
686  }
687  TSource[] array = new TSource[count];
688  int arrayIndex;
689  if (_appending)
690  {
691  arrayIndex = 0;
692  }
693  else
694  {
695  array[0] = _item;
696  arrayIndex = 1;
697  }
698  EnumerableHelpers.Copy(_source, array, arrayIndex, count - 1);
699  if (_appending)
700  {
701  array[array.Length - 1] = _item;
702  }
703  return array;
704  }
705 
706  public override List<TSource> ToList()
707  {
708  int count = GetCount(onlyIfCheap: true);
709  List<TSource> list = (count == -1) ? new List<TSource>() : new List<TSource>(count);
710  if (!_appending)
711  {
712  list.Add(_item);
713  }
714  list.AddRange(_source);
715  if (_appending)
716  {
717  list.Add(_item);
718  }
719  return list;
720  }
721 
722  public override int GetCount(bool onlyIfCheap)
723  {
724  IIListProvider<TSource> iIListProvider = _source as IIListProvider<TSource>;
725  if (iIListProvider != null)
726  {
727  int count = iIListProvider.GetCount(onlyIfCheap);
728  if (count != -1)
729  {
730  return count + 1;
731  }
732  return -1;
733  }
734  if (onlyIfCheap && !(_source is ICollection<TSource>))
735  {
736  return -1;
737  }
738  return _source.Count() + 1;
739  }
740  }
741 
742  private class AppendPrependN<TSource> : AppendPrependIterator<TSource>
743  {
744  private readonly SingleLinkedNode<TSource> _prepended;
745 
746  private readonly SingleLinkedNode<TSource> _appended;
747 
748  private readonly int _prependCount;
749 
750  private readonly int _appendCount;
751 
752  private SingleLinkedNode<TSource> _node;
753 
754  public AppendPrependN(IEnumerable<TSource> source, SingleLinkedNode<TSource> prepended, SingleLinkedNode<TSource> appended, int prependCount, int appendCount)
755  : base(source)
756  {
757  _prepended = prepended;
758  _appended = appended;
759  _prependCount = prependCount;
760  _appendCount = appendCount;
761  }
762 
763  public override Iterator<TSource> Clone()
764  {
765  return new AppendPrependN<TSource>(_source, _prepended, _appended, _prependCount, _appendCount);
766  }
767 
768  public override bool MoveNext()
769  {
770  switch (state)
771  {
772  case 1:
773  _node = _prepended;
774  state = 2;
775  goto case 2;
776  case 2:
777  if (_node != null)
778  {
779  current = _node.Item;
780  _node = _node.Linked;
781  return true;
782  }
783  GetSourceEnumerator();
784  state = 3;
785  goto case 3;
786  case 3:
787  if (LoadFromEnumerator())
788  {
789  return true;
790  }
791  if (_appended == null)
792  {
793  return false;
794  }
795  enumerator = _appended.GetEnumerator(_appendCount);
796  state = 4;
797  goto case 4;
798  case 4:
799  return LoadFromEnumerator();
800  default:
801  Dispose();
802  return false;
803  }
804  }
805 
806  public override AppendPrependIterator<TSource> Append(TSource item)
807  {
808  SingleLinkedNode<TSource> appended = (_appended != null) ? _appended.Add(item) : new SingleLinkedNode<TSource>(item);
809  return new AppendPrependN<TSource>(_source, _prepended, appended, _prependCount, _appendCount + 1);
810  }
811 
812  public override AppendPrependIterator<TSource> Prepend(TSource item)
813  {
814  SingleLinkedNode<TSource> prepended = (_prepended != null) ? _prepended.Add(item) : new SingleLinkedNode<TSource>(item);
815  return new AppendPrependN<TSource>(_source, prepended, _appended, _prependCount + 1, _appendCount);
816  }
817 
818  private TSource[] LazyToArray()
819  {
820  SparseArrayBuilder<TSource> sparseArrayBuilder = new SparseArrayBuilder<TSource>(initialize: true);
821  if (_prepended != null)
822  {
823  sparseArrayBuilder.Reserve(_prependCount);
824  }
825  sparseArrayBuilder.AddRange(_source);
826  if (_appended != null)
827  {
828  sparseArrayBuilder.Reserve(_appendCount);
829  }
830  TSource[] array = sparseArrayBuilder.ToArray();
831  int num = 0;
832  for (SingleLinkedNode<TSource> singleLinkedNode = _prepended; singleLinkedNode != null; singleLinkedNode = singleLinkedNode.Linked)
833  {
834  array[num++] = singleLinkedNode.Item;
835  }
836  num = array.Length - 1;
837  for (SingleLinkedNode<TSource> singleLinkedNode2 = _appended; singleLinkedNode2 != null; singleLinkedNode2 = singleLinkedNode2.Linked)
838  {
839  array[num--] = singleLinkedNode2.Item;
840  }
841  return array;
842  }
843 
844  public override TSource[] ToArray()
845  {
846  int count = GetCount(onlyIfCheap: true);
847  if (count == -1)
848  {
849  return LazyToArray();
850  }
851  TSource[] array = new TSource[count];
852  int num = 0;
853  for (SingleLinkedNode<TSource> singleLinkedNode = _prepended; singleLinkedNode != null; singleLinkedNode = singleLinkedNode.Linked)
854  {
855  array[num] = singleLinkedNode.Item;
856  num++;
857  }
858  ICollection<TSource> collection = _source as ICollection<TSource>;
859  if (collection != null)
860  {
861  collection.CopyTo(array, num);
862  }
863  else
864  {
865  foreach (TSource item in _source)
866  {
867  TSource val = array[num] = item;
868  num++;
869  }
870  }
871  num = array.Length;
872  for (SingleLinkedNode<TSource> singleLinkedNode2 = _appended; singleLinkedNode2 != null; singleLinkedNode2 = singleLinkedNode2.Linked)
873  {
874  num--;
875  array[num] = singleLinkedNode2.Item;
876  }
877  return array;
878  }
879 
880  public override List<TSource> ToList()
881  {
882  int count = GetCount(onlyIfCheap: true);
883  List<TSource> list = (count == -1) ? new List<TSource>() : new List<TSource>(count);
884  for (SingleLinkedNode<TSource> singleLinkedNode = _prepended; singleLinkedNode != null; singleLinkedNode = singleLinkedNode.Linked)
885  {
886  list.Add(singleLinkedNode.Item);
887  }
888  list.AddRange(_source);
889  if (_appended != null)
890  {
891  IEnumerator<TSource> enumerator = _appended.GetEnumerator(_appendCount);
892  while (enumerator.MoveNext())
893  {
894  list.Add(enumerator.Current);
895  }
896  }
897  return list;
898  }
899 
900  public override int GetCount(bool onlyIfCheap)
901  {
902  IIListProvider<TSource> iIListProvider = _source as IIListProvider<TSource>;
903  if (iIListProvider != null)
904  {
905  int count = iIListProvider.GetCount(onlyIfCheap);
906  if (count != -1)
907  {
908  return count + _appendCount + _prependCount;
909  }
910  return -1;
911  }
912  if (onlyIfCheap && !(_source is ICollection<TSource>))
913  {
914  return -1;
915  }
916  return _source.Count() + _appendCount + _prependCount;
917  }
918  }
919 
927  [global::__DynamicallyInvokable]
928  public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
929  {
930  if (source == null)
931  {
932  throw Error.ArgumentNull("source");
933  }
934  if (predicate == null)
935  {
936  throw Error.ArgumentNull("predicate");
937  }
938  if (source is Iterator<TSource>)
939  {
940  return ((Iterator<TSource>)source).Where(predicate);
941  }
942  if (source is TSource[])
943  {
944  return new WhereArrayIterator<TSource>((TSource[])source, predicate);
945  }
946  if (source is List<TSource>)
947  {
948  return new WhereListIterator<TSource>((List<TSource>)source, predicate);
949  }
950  return new WhereEnumerableIterator<TSource>(source, predicate);
951  }
952 
960  [global::__DynamicallyInvokable]
961  public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
962  {
963  if (source == null)
964  {
965  throw Error.ArgumentNull("source");
966  }
967  if (predicate == null)
968  {
969  throw Error.ArgumentNull("predicate");
970  }
971  return WhereIterator(source, predicate);
972  }
973 
974  private static IEnumerable<TSource> WhereIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
975  {
976  int index = -1;
977  foreach (TSource item in source)
978  {
979  index = checked(index + 1);
980  if (predicate(item, index))
981  {
982  yield return item;
983  }
984  }
985  }
986 
995  [global::__DynamicallyInvokable]
996  public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
997  {
998  if (source == null)
999  {
1000  throw Error.ArgumentNull("source");
1001  }
1002  if (selector == null)
1003  {
1004  throw Error.ArgumentNull("selector");
1005  }
1006  if (source is Iterator<TSource>)
1007  {
1008  return ((Iterator<TSource>)source).Select(selector);
1009  }
1010  if (source is TSource[])
1011  {
1012  return new WhereSelectArrayIterator<TSource, TResult>((TSource[])source, null, selector);
1013  }
1014  if (source is List<TSource>)
1015  {
1016  return new WhereSelectListIterator<TSource, TResult>((List<TSource>)source, null, selector);
1017  }
1018  return new WhereSelectEnumerableIterator<TSource, TResult>(source, null, selector);
1019  }
1020 
1029  [global::__DynamicallyInvokable]
1030  public static IEnumerable<TResult> Select<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, TResult> selector)
1031  {
1032  if (source == null)
1033  {
1034  throw Error.ArgumentNull("source");
1035  }
1036  if (selector == null)
1037  {
1038  throw Error.ArgumentNull("selector");
1039  }
1040  return SelectIterator(source, selector);
1041  }
1042 
1043  private static IEnumerable<TResult> SelectIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, int, TResult> selector)
1044  {
1045  int index = -1;
1046  foreach (TSource item in source)
1047  {
1048  index = checked(index + 1);
1049  yield return selector(item, index);
1050  }
1051  }
1052 
1053  private static Func<TSource, bool> CombinePredicates<TSource>(Func<TSource, bool> predicate1, Func<TSource, bool> predicate2)
1054  {
1055  return delegate(TSource x)
1056  {
1057  if (predicate1(x))
1058  {
1059  return predicate2(x);
1060  }
1061  return false;
1062  };
1063  }
1064 
1065  private static Func<TSource, TResult> CombineSelectors<TSource, TMiddle, TResult>(Func<TSource, TMiddle> selector1, Func<TMiddle, TResult> selector2)
1066  {
1067  return (TSource x) => selector2(selector1(x));
1068  }
1069 
1078  [global::__DynamicallyInvokable]
1080  {
1081  if (source == null)
1082  {
1083  throw Error.ArgumentNull("source");
1084  }
1085  if (selector == null)
1086  {
1087  throw Error.ArgumentNull("selector");
1088  }
1089  return SelectManyIterator(source, selector);
1090  }
1091 
1092  private static IEnumerable<TResult> SelectManyIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
1093  {
1094  foreach (TSource item in source)
1095  {
1096  foreach (TResult item2 in selector(item))
1097  {
1098  yield return item2;
1099  }
1100  }
1101  }
1102 
1111  [global::__DynamicallyInvokable]
1112  public static IEnumerable<TResult> SelectMany<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
1113  {
1114  if (source == null)
1115  {
1116  throw Error.ArgumentNull("source");
1117  }
1118  if (selector == null)
1119  {
1120  throw Error.ArgumentNull("selector");
1121  }
1122  return SelectManyIterator(source, selector);
1123  }
1124 
1125  private static IEnumerable<TResult> SelectManyIterator<TSource, TResult>(IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
1126  {
1127  int index = -1;
1128  foreach (TSource item in source)
1129  {
1130  index = checked(index + 1);
1131  foreach (TResult item2 in selector(item, index))
1132  {
1133  yield return item2;
1134  }
1135  }
1136  }
1137 
1148  [global::__DynamicallyInvokable]
1149  public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
1150  {
1151  if (source == null)
1152  {
1153  throw Error.ArgumentNull("source");
1154  }
1155  if (collectionSelector == null)
1156  {
1157  throw Error.ArgumentNull("collectionSelector");
1158  }
1159  if (resultSelector == null)
1160  {
1161  throw Error.ArgumentNull("resultSelector");
1162  }
1163  return SelectManyIterator(source, collectionSelector, resultSelector);
1164  }
1165 
1166  private static IEnumerable<TResult> SelectManyIterator<TSource, TCollection, TResult>(IEnumerable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
1167  {
1168  int index = -1;
1169  foreach (TSource element in source)
1170  {
1171  index = checked(index + 1);
1172  foreach (TCollection item in collectionSelector(element, index))
1173  {
1174  yield return resultSelector(element, item);
1175  }
1176  }
1177  }
1178 
1189  [global::__DynamicallyInvokable]
1190  public static IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(this IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
1191  {
1192  if (source == null)
1193  {
1194  throw Error.ArgumentNull("source");
1195  }
1196  if (collectionSelector == null)
1197  {
1198  throw Error.ArgumentNull("collectionSelector");
1199  }
1200  if (resultSelector == null)
1201  {
1202  throw Error.ArgumentNull("resultSelector");
1203  }
1204  return SelectManyIterator(source, collectionSelector, resultSelector);
1205  }
1206 
1207  private static IEnumerable<TResult> SelectManyIterator<TSource, TCollection, TResult>(IEnumerable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
1208  {
1209  foreach (TSource element in source)
1210  {
1211  foreach (TCollection item in collectionSelector(element))
1212  {
1213  yield return resultSelector(element, item);
1214  }
1215  }
1216  }
1217 
1225  [global::__DynamicallyInvokable]
1226  public static IEnumerable<TSource> Take<TSource>(this IEnumerable<TSource> source, int count)
1227  {
1228  if (source == null)
1229  {
1230  throw Error.ArgumentNull("source");
1231  }
1232  return TakeIterator(source, count);
1233  }
1234 
1235  private static IEnumerable<TSource> TakeIterator<TSource>(IEnumerable<TSource> source, int count)
1236  {
1237  if (count > 0)
1238  {
1239  foreach (TSource item in source)
1240  {
1241  yield return item;
1242  int num = count - 1;
1243  count = num;
1244  if (num == 0)
1245  {
1246  break;
1247  }
1248  }
1249  }
1250  }
1251 
1259  [global::__DynamicallyInvokable]
1260  public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
1261  {
1262  if (source == null)
1263  {
1264  throw Error.ArgumentNull("source");
1265  }
1266  if (predicate == null)
1267  {
1268  throw Error.ArgumentNull("predicate");
1269  }
1270  return TakeWhileIterator(source, predicate);
1271  }
1272 
1273  private static IEnumerable<TSource> TakeWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate)
1274  {
1275  foreach (TSource item in source)
1276  {
1277  if (!predicate(item))
1278  {
1279  break;
1280  }
1281  yield return item;
1282  }
1283  }
1284 
1292  [global::__DynamicallyInvokable]
1293  public static IEnumerable<TSource> TakeWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
1294  {
1295  if (source == null)
1296  {
1297  throw Error.ArgumentNull("source");
1298  }
1299  if (predicate == null)
1300  {
1301  throw Error.ArgumentNull("predicate");
1302  }
1303  return TakeWhileIterator(source, predicate);
1304  }
1305 
1306  private static IEnumerable<TSource> TakeWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
1307  {
1308  int index = -1;
1309  foreach (TSource item in source)
1310  {
1311  index = checked(index + 1);
1312  if (!predicate(item, index))
1313  {
1314  break;
1315  }
1316  yield return item;
1317  }
1318  }
1319 
1327  [global::__DynamicallyInvokable]
1328  public static IEnumerable<TSource> Skip<TSource>(this IEnumerable<TSource> source, int count)
1329  {
1330  if (source == null)
1331  {
1332  throw Error.ArgumentNull("source");
1333  }
1334  return SkipIterator(source, count);
1335  }
1336 
1337  private static IEnumerable<TSource> SkipIterator<TSource>(IEnumerable<TSource> source, int count)
1338  {
1339  using (IEnumerator<TSource> e = source.GetEnumerator())
1340  {
1341  while (count > 0 && e.MoveNext())
1342  {
1343  count--;
1344  }
1345  if (count <= 0)
1346  {
1347  while (e.MoveNext())
1348  {
1349  yield return e.Current;
1350  }
1351  }
1352  }
1353  }
1354 
1362  [global::__DynamicallyInvokable]
1363  public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
1364  {
1365  if (source == null)
1366  {
1367  throw Error.ArgumentNull("source");
1368  }
1369  if (predicate == null)
1370  {
1371  throw Error.ArgumentNull("predicate");
1372  }
1373  return SkipWhileIterator(source, predicate);
1374  }
1375 
1376  private static IEnumerable<TSource> SkipWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, bool> predicate)
1377  {
1378  bool yielding = false;
1379  foreach (TSource item in source)
1380  {
1381  if (!yielding && !predicate(item))
1382  {
1383  yielding = true;
1384  }
1385  if (yielding)
1386  {
1387  yield return item;
1388  }
1389  }
1390  }
1391 
1399  [global::__DynamicallyInvokable]
1400  public static IEnumerable<TSource> SkipWhile<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
1401  {
1402  if (source == null)
1403  {
1404  throw Error.ArgumentNull("source");
1405  }
1406  if (predicate == null)
1407  {
1408  throw Error.ArgumentNull("predicate");
1409  }
1410  return SkipWhileIterator(source, predicate);
1411  }
1412 
1413  private static IEnumerable<TSource> SkipWhileIterator<TSource>(IEnumerable<TSource> source, Func<TSource, int, bool> predicate)
1414  {
1415  int index = -1;
1416  bool yielding = false;
1417  foreach (TSource item in source)
1418  {
1419  index = checked(index + 1);
1420  if (!yielding && !predicate(item, index))
1421  {
1422  yielding = true;
1423  }
1424  if (yielding)
1425  {
1426  yield return item;
1427  }
1428  }
1429  }
1430 
1444  [global::__DynamicallyInvokable]
1445  public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector)
1446  {
1447  if (outer == null)
1448  {
1449  throw Error.ArgumentNull("outer");
1450  }
1451  if (inner == null)
1452  {
1453  throw Error.ArgumentNull("inner");
1454  }
1455  if (outerKeySelector == null)
1456  {
1457  throw Error.ArgumentNull("outerKeySelector");
1458  }
1459  if (innerKeySelector == null)
1460  {
1461  throw Error.ArgumentNull("innerKeySelector");
1462  }
1463  if (resultSelector == null)
1464  {
1465  throw Error.ArgumentNull("resultSelector");
1466  }
1467  return JoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
1468  }
1469 
1484  [global::__DynamicallyInvokable]
1485  public static IEnumerable<TResult> Join<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1486  {
1487  if (outer == null)
1488  {
1489  throw Error.ArgumentNull("outer");
1490  }
1491  if (inner == null)
1492  {
1493  throw Error.ArgumentNull("inner");
1494  }
1495  if (outerKeySelector == null)
1496  {
1497  throw Error.ArgumentNull("outerKeySelector");
1498  }
1499  if (innerKeySelector == null)
1500  {
1501  throw Error.ArgumentNull("innerKeySelector");
1502  }
1503  if (resultSelector == null)
1504  {
1505  throw Error.ArgumentNull("resultSelector");
1506  }
1507  return JoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
1508  }
1509 
1510  private static IEnumerable<TResult> JoinIterator<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1511  {
1512  Lookup<TKey, TInner> lookup = Lookup<TKey, TInner>.CreateForJoin(inner, innerKeySelector, comparer);
1513  foreach (TOuter item in outer)
1514  {
1515  Lookup<TKey, TInner>.Grouping g = lookup.GetGrouping(outerKeySelector(item), create: false);
1516  if (g != null)
1517  {
1518  for (int i = 0; i < g.count; i++)
1519  {
1520  yield return resultSelector(item, g.elements[i]);
1521  }
1522  }
1523  }
1524  }
1525 
1539  [global::__DynamicallyInvokable]
1540  public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector)
1541  {
1542  if (outer == null)
1543  {
1544  throw Error.ArgumentNull("outer");
1545  }
1546  if (inner == null)
1547  {
1548  throw Error.ArgumentNull("inner");
1549  }
1550  if (outerKeySelector == null)
1551  {
1552  throw Error.ArgumentNull("outerKeySelector");
1553  }
1554  if (innerKeySelector == null)
1555  {
1556  throw Error.ArgumentNull("innerKeySelector");
1557  }
1558  if (resultSelector == null)
1559  {
1560  throw Error.ArgumentNull("resultSelector");
1561  }
1562  return GroupJoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, null);
1563  }
1564 
1579  [global::__DynamicallyInvokable]
1580  public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey, TResult>(this IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1581  {
1582  if (outer == null)
1583  {
1584  throw Error.ArgumentNull("outer");
1585  }
1586  if (inner == null)
1587  {
1588  throw Error.ArgumentNull("inner");
1589  }
1590  if (outerKeySelector == null)
1591  {
1592  throw Error.ArgumentNull("outerKeySelector");
1593  }
1594  if (innerKeySelector == null)
1595  {
1596  throw Error.ArgumentNull("innerKeySelector");
1597  }
1598  if (resultSelector == null)
1599  {
1600  throw Error.ArgumentNull("resultSelector");
1601  }
1602  return GroupJoinIterator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
1603  }
1604 
1605  private static IEnumerable<TResult> GroupJoinIterator<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter> outer, IEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1606  {
1607  Lookup<TKey, TInner> lookup = Lookup<TKey, TInner>.CreateForJoin(inner, innerKeySelector, comparer);
1608  foreach (TOuter item in outer)
1609  {
1610  yield return resultSelector(item, lookup[outerKeySelector(item)]);
1611  }
1612  }
1613 
1622  [global::__DynamicallyInvokable]
1623  public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
1624  {
1625  return new OrderedEnumerable<TSource, TKey>(source, keySelector, null, descending: false);
1626  }
1627 
1637  [global::__DynamicallyInvokable]
1638  public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
1639  {
1640  return new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, descending: false);
1641  }
1642 
1651  [global::__DynamicallyInvokable]
1652  public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
1653  {
1654  return new OrderedEnumerable<TSource, TKey>(source, keySelector, null, descending: true);
1655  }
1656 
1666  [global::__DynamicallyInvokable]
1667  public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
1668  {
1669  return new OrderedEnumerable<TSource, TKey>(source, keySelector, comparer, descending: true);
1670  }
1671 
1680  [global::__DynamicallyInvokable]
1681  public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
1682  {
1683  if (source == null)
1684  {
1685  throw Error.ArgumentNull("source");
1686  }
1687  return source.CreateOrderedEnumerable(keySelector, null, descending: false);
1688  }
1689 
1699  [global::__DynamicallyInvokable]
1700  public static IOrderedEnumerable<TSource> ThenBy<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
1701  {
1702  if (source == null)
1703  {
1704  throw Error.ArgumentNull("source");
1705  }
1706  return source.CreateOrderedEnumerable(keySelector, comparer, descending: false);
1707  }
1708 
1717  [global::__DynamicallyInvokable]
1718  public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector)
1719  {
1720  if (source == null)
1721  {
1722  throw Error.ArgumentNull("source");
1723  }
1724  return source.CreateOrderedEnumerable(keySelector, null, descending: true);
1725  }
1726 
1736  [global::__DynamicallyInvokable]
1737  public static IOrderedEnumerable<TSource> ThenByDescending<TSource, TKey>(this IOrderedEnumerable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
1738  {
1739  if (source == null)
1740  {
1741  throw Error.ArgumentNull("source");
1742  }
1743  return source.CreateOrderedEnumerable(keySelector, comparer, descending: true);
1744  }
1745 
1754  [global::__DynamicallyInvokable]
1755  public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
1756  {
1757  return new GroupedEnumerable<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, null);
1758  }
1759 
1769  [global::__DynamicallyInvokable]
1770  public static IEnumerable<IGrouping<TKey, TSource>> GroupBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
1771  {
1772  return new GroupedEnumerable<TSource, TKey, TSource>(source, keySelector, IdentityFunction<TSource>.Instance, comparer);
1773  }
1774 
1785  [global::__DynamicallyInvokable]
1786  public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
1787  {
1788  return new GroupedEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, null);
1789  }
1790 
1802  [global::__DynamicallyInvokable]
1803  public static IEnumerable<IGrouping<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
1804  {
1805  return new GroupedEnumerable<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
1806  }
1807 
1816  [global::__DynamicallyInvokable]
1817  public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector)
1818  {
1819  return new GroupedEnumerable<TSource, TKey, TSource, TResult>(source, keySelector, IdentityFunction<TSource>.Instance, resultSelector, null);
1820  }
1821 
1832  [global::__DynamicallyInvokable]
1833  public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector)
1834  {
1835  return new GroupedEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, null);
1836  }
1837 
1847  [global::__DynamicallyInvokable]
1848  public static IEnumerable<TResult> GroupBy<TSource, TKey, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TKey, IEnumerable<TSource>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1849  {
1850  return new GroupedEnumerable<TSource, TKey, TSource, TResult>(source, keySelector, IdentityFunction<TSource>.Instance, resultSelector, comparer);
1851  }
1852 
1864  [global::__DynamicallyInvokable]
1865  public static IEnumerable<TResult> GroupBy<TSource, TKey, TElement, TResult>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer)
1866  {
1867  return new GroupedEnumerable<TSource, TKey, TElement, TResult>(source, keySelector, elementSelector, resultSelector, comparer);
1868  }
1869 
1877  [global::__DynamicallyInvokable]
1879  {
1880  if (first == null)
1881  {
1882  throw Error.ArgumentNull("first");
1883  }
1884  if (second == null)
1885  {
1886  throw Error.ArgumentNull("second");
1887  }
1888  return ConcatIterator(first, second);
1889  }
1890 
1891  private static IEnumerable<TSource> ConcatIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second)
1892  {
1893  foreach (TSource item in first)
1894  {
1895  yield return item;
1896  }
1897  foreach (TSource item2 in second)
1898  {
1899  yield return item2;
1900  }
1901  }
1902 
1913  [global::__DynamicallyInvokable]
1914  public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
1915  {
1916  if (first == null)
1917  {
1918  throw Error.ArgumentNull("first");
1919  }
1920  if (second == null)
1921  {
1922  throw Error.ArgumentNull("second");
1923  }
1924  if (resultSelector == null)
1925  {
1926  throw Error.ArgumentNull("resultSelector");
1927  }
1928  return ZipIterator(first, second, resultSelector);
1929  }
1930 
1931  private static IEnumerable<TResult> ZipIterator<TFirst, TSecond, TResult>(IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
1932  {
1933  using (IEnumerator<TFirst> e3 = first.GetEnumerator())
1934  {
1935  using (IEnumerator<TSecond> e2 = second.GetEnumerator())
1936  {
1937  while (e3.MoveNext() && e2.MoveNext())
1938  {
1939  yield return resultSelector(e3.Current, e2.Current);
1940  }
1941  }
1942  }
1943  }
1944 
1951  [global::__DynamicallyInvokable]
1953  {
1954  if (source == null)
1955  {
1956  throw Error.ArgumentNull("source");
1957  }
1958  return DistinctIterator(source, null);
1959  }
1960 
1968  [global::__DynamicallyInvokable]
1970  {
1971  if (source == null)
1972  {
1973  throw Error.ArgumentNull("source");
1974  }
1975  return DistinctIterator(source, comparer);
1976  }
1977 
1978  private static IEnumerable<TSource> DistinctIterator<TSource>(IEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
1979  {
1980  Set<TSource> set = new Set<TSource>(comparer);
1981  foreach (TSource item in source)
1982  {
1983  if (set.Add(item))
1984  {
1985  yield return item;
1986  }
1987  }
1988  }
1989 
1997  [global::__DynamicallyInvokable]
1999  {
2000  if (first == null)
2001  {
2002  throw Error.ArgumentNull("first");
2003  }
2004  if (second == null)
2005  {
2006  throw Error.ArgumentNull("second");
2007  }
2008  return UnionIterator(first, second, null);
2009  }
2010 
2019  [global::__DynamicallyInvokable]
2021  {
2022  if (first == null)
2023  {
2024  throw Error.ArgumentNull("first");
2025  }
2026  if (second == null)
2027  {
2028  throw Error.ArgumentNull("second");
2029  }
2030  return UnionIterator(first, second, comparer);
2031  }
2032 
2033  private static IEnumerable<TSource> UnionIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
2034  {
2035  Set<TSource> set = new Set<TSource>(comparer);
2036  foreach (TSource item in first)
2037  {
2038  if (set.Add(item))
2039  {
2040  yield return item;
2041  }
2042  }
2043  foreach (TSource item2 in second)
2044  {
2045  if (set.Add(item2))
2046  {
2047  yield return item2;
2048  }
2049  }
2050  }
2051 
2059  [global::__DynamicallyInvokable]
2061  {
2062  if (first == null)
2063  {
2064  throw Error.ArgumentNull("first");
2065  }
2066  if (second == null)
2067  {
2068  throw Error.ArgumentNull("second");
2069  }
2070  return IntersectIterator(first, second, null);
2071  }
2072 
2081  [global::__DynamicallyInvokable]
2083  {
2084  if (first == null)
2085  {
2086  throw Error.ArgumentNull("first");
2087  }
2088  if (second == null)
2089  {
2090  throw Error.ArgumentNull("second");
2091  }
2092  return IntersectIterator(first, second, comparer);
2093  }
2094 
2095  private static IEnumerable<TSource> IntersectIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
2096  {
2097  Set<TSource> set = new Set<TSource>(comparer);
2098  foreach (TSource item in second)
2099  {
2100  set.Add(item);
2101  }
2102  foreach (TSource item2 in first)
2103  {
2104  if (set.Remove(item2))
2105  {
2106  yield return item2;
2107  }
2108  }
2109  }
2110 
2118  [global::__DynamicallyInvokable]
2120  {
2121  if (first == null)
2122  {
2123  throw Error.ArgumentNull("first");
2124  }
2125  if (second == null)
2126  {
2127  throw Error.ArgumentNull("second");
2128  }
2129  return ExceptIterator(first, second, null);
2130  }
2131 
2140  [global::__DynamicallyInvokable]
2142  {
2143  if (first == null)
2144  {
2145  throw Error.ArgumentNull("first");
2146  }
2147  if (second == null)
2148  {
2149  throw Error.ArgumentNull("second");
2150  }
2151  return ExceptIterator(first, second, comparer);
2152  }
2153 
2154  private static IEnumerable<TSource> ExceptIterator<TSource>(IEnumerable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
2155  {
2156  Set<TSource> set = new Set<TSource>(comparer);
2157  foreach (TSource item in second)
2158  {
2159  set.Add(item);
2160  }
2161  foreach (TSource item2 in first)
2162  {
2163  if (set.Add(item2))
2164  {
2165  yield return item2;
2166  }
2167  }
2168  }
2169 
2176  [global::__DynamicallyInvokable]
2178  {
2179  if (source == null)
2180  {
2181  throw Error.ArgumentNull("source");
2182  }
2183  return ReverseIterator(source);
2184  }
2185 
2186  private static IEnumerable<TSource> ReverseIterator<TSource>(IEnumerable<TSource> source)
2187  {
2188  Buffer<TSource> buffer = new Buffer<TSource>(source);
2189  for (int i = buffer.count - 1; i >= 0; i--)
2190  {
2191  yield return buffer.items[i];
2192  }
2193  }
2194 
2203  [global::__DynamicallyInvokable]
2205  {
2206  return first.SequenceEqual(second, null);
2207  }
2208 
2218  [global::__DynamicallyInvokable]
2220  {
2221  if (comparer == null)
2222  {
2224  }
2225  if (first == null)
2226  {
2227  throw Error.ArgumentNull("first");
2228  }
2229  if (second == null)
2230  {
2231  throw Error.ArgumentNull("second");
2232  }
2233  using (IEnumerator<TSource> enumerator = first.GetEnumerator())
2234  {
2235  using (IEnumerator<TSource> enumerator2 = second.GetEnumerator())
2236  {
2237  while (enumerator.MoveNext())
2238  {
2239  if (!enumerator2.MoveNext() || !comparer.Equals(enumerator.Current, enumerator2.Current))
2240  {
2241  return false;
2242  }
2243  }
2244  if (enumerator2.MoveNext())
2245  {
2246  return false;
2247  }
2248  }
2249  }
2250  return true;
2251  }
2252 
2257  [global::__DynamicallyInvokable]
2259  {
2260  return source;
2261  }
2262 
2269  [global::__DynamicallyInvokable]
2270  public static TSource[] ToArray<TSource>(this IEnumerable<TSource> source)
2271  {
2272  if (source == null)
2273  {
2274  throw Error.ArgumentNull("source");
2275  }
2276  return new Buffer<TSource>(source).ToArray();
2277  }
2278 
2285  [global::__DynamicallyInvokable]
2287  {
2288  if (source == null)
2289  {
2290  throw Error.ArgumentNull("source");
2291  }
2292  return new List<TSource>(source);
2293  }
2294 
2306  [global::__DynamicallyInvokable]
2307  public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
2308  {
2309  return source.ToDictionary(keySelector, IdentityFunction<TSource>.Instance, null);
2310  }
2311 
2324  [global::__DynamicallyInvokable]
2325  public static Dictionary<TKey, TSource> ToDictionary<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
2326  {
2327  return source.ToDictionary(keySelector, IdentityFunction<TSource>.Instance, comparer);
2328  }
2329 
2343  [global::__DynamicallyInvokable]
2344  public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
2345  {
2346  return source.ToDictionary(keySelector, elementSelector, null);
2347  }
2348 
2363  [global::__DynamicallyInvokable]
2364  public static Dictionary<TKey, TElement> ToDictionary<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
2365  {
2366  if (source == null)
2367  {
2368  throw Error.ArgumentNull("source");
2369  }
2370  if (keySelector == null)
2371  {
2372  throw Error.ArgumentNull("keySelector");
2373  }
2374  if (elementSelector == null)
2375  {
2376  throw Error.ArgumentNull("elementSelector");
2377  }
2378  Dictionary<TKey, TElement> dictionary = new Dictionary<TKey, TElement>(comparer);
2379  foreach (TSource item in source)
2380  {
2381  dictionary.Add(keySelector(item), elementSelector(item));
2382  }
2383  return dictionary;
2384  }
2385 
2394  [global::__DynamicallyInvokable]
2395  public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
2396  {
2397  return Lookup<TKey, TSource>.Create(source, keySelector, IdentityFunction<TSource>.Instance, null);
2398  }
2399 
2409  [global::__DynamicallyInvokable]
2410  public static ILookup<TKey, TSource> ToLookup<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
2411  {
2412  return Lookup<TKey, TSource>.Create(source, keySelector, IdentityFunction<TSource>.Instance, comparer);
2413  }
2414 
2425  [global::__DynamicallyInvokable]
2426  public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
2427  {
2428  return Lookup<TKey, TElement>.Create(source, keySelector, elementSelector, null);
2429  }
2430 
2442  [global::__DynamicallyInvokable]
2443  public static ILookup<TKey, TElement> ToLookup<TSource, TKey, TElement>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
2444  {
2445  return Lookup<TKey, TElement>.Create(source, keySelector, elementSelector, comparer);
2446  }
2447 
2454  [global::__DynamicallyInvokable]
2456  {
2457  return source.DefaultIfEmpty(default(TSource));
2458  }
2459 
2465  [global::__DynamicallyInvokable]
2466  public static IEnumerable<TSource> DefaultIfEmpty<TSource>(this IEnumerable<TSource> source, TSource defaultValue)
2467  {
2468  if (source == null)
2469  {
2470  throw Error.ArgumentNull("source");
2471  }
2472  return DefaultIfEmptyIterator(source, defaultValue);
2473  }
2474 
2475  private static IEnumerable<TSource> DefaultIfEmptyIterator<TSource>(IEnumerable<TSource> source, TSource defaultValue)
2476  {
2477  using (IEnumerator<TSource> e = source.GetEnumerator())
2478  {
2479  if (e.MoveNext())
2480  {
2481  do
2482  {
2483  yield return e.Current;
2484  }
2485  while (e.MoveNext());
2486  }
2487  else
2488  {
2489  yield return defaultValue;
2490  }
2491  }
2492  }
2493 
2500  [global::__DynamicallyInvokable]
2502  {
2503  if (source == null)
2504  {
2505  throw Error.ArgumentNull("source");
2506  }
2507  return OfTypeIterator<TResult>(source);
2508  }
2509 
2510  private static IEnumerable<TResult> OfTypeIterator<TResult>(IEnumerable source)
2511  {
2512  foreach (object item in source)
2513  {
2514  if (item is TResult)
2515  {
2516  yield return (TResult)item;
2517  }
2518  }
2519  }
2520 
2528  [global::__DynamicallyInvokable]
2530  {
2531  IEnumerable<TResult> enumerable = source as IEnumerable<TResult>;
2532  if (enumerable != null)
2533  {
2534  return enumerable;
2535  }
2536  if (source == null)
2537  {
2538  throw Error.ArgumentNull("source");
2539  }
2540  return CastIterator<TResult>(source);
2541  }
2542 
2543  private static IEnumerable<TResult> CastIterator<TResult>(IEnumerable source)
2544  {
2545  foreach (object item in source)
2546  {
2547  yield return (TResult)item;
2548  }
2549  }
2550 
2558  [global::__DynamicallyInvokable]
2559  public static TSource First<TSource>(this IEnumerable<TSource> source)
2560  {
2561  if (source == null)
2562  {
2563  throw Error.ArgumentNull("source");
2564  }
2565  IList<TSource> list = source as IList<TSource>;
2566  if (list != null)
2567  {
2568  if (list.Count > 0)
2569  {
2570  return list[0];
2571  }
2572  }
2573  else
2574  {
2575  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2576  {
2577  if (enumerator.MoveNext())
2578  {
2579  return enumerator.Current;
2580  }
2581  }
2582  }
2583  throw Error.NoElements();
2584  }
2585 
2594  [global::__DynamicallyInvokable]
2595  public static TSource First<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2596  {
2597  if (source == null)
2598  {
2599  throw Error.ArgumentNull("source");
2600  }
2601  if (predicate == null)
2602  {
2603  throw Error.ArgumentNull("predicate");
2604  }
2605  foreach (TSource item in source)
2606  {
2607  if (predicate(item))
2608  {
2609  return item;
2610  }
2611  }
2612  throw Error.NoMatch();
2613  }
2614 
2622  [global::__DynamicallyInvokable]
2623  public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source)
2624  {
2625  if (source == null)
2626  {
2627  throw Error.ArgumentNull("source");
2628  }
2629  IList<TSource> list = source as IList<TSource>;
2630  if (list != null)
2631  {
2632  if (list.Count > 0)
2633  {
2634  return list[0];
2635  }
2636  }
2637  else
2638  {
2639  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2640  {
2641  if (enumerator.MoveNext())
2642  {
2643  return enumerator.Current;
2644  }
2645  }
2646  }
2647  return default(TSource);
2648  }
2649 
2658  [global::__DynamicallyInvokable]
2659  public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2660  {
2661  if (source == null)
2662  {
2663  throw Error.ArgumentNull("source");
2664  }
2665  if (predicate == null)
2666  {
2667  throw Error.ArgumentNull("predicate");
2668  }
2669  foreach (TSource item in source)
2670  {
2671  if (predicate(item))
2672  {
2673  return item;
2674  }
2675  }
2676  return default(TSource);
2677  }
2678 
2686  [global::__DynamicallyInvokable]
2687  public static TSource Last<TSource>(this IEnumerable<TSource> source)
2688  {
2689  if (source == null)
2690  {
2691  throw Error.ArgumentNull("source");
2692  }
2693  IList<TSource> list = source as IList<TSource>;
2694  if (list != null)
2695  {
2696  int count = list.Count;
2697  if (count > 0)
2698  {
2699  return list[count - 1];
2700  }
2701  }
2702  else
2703  {
2704  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2705  {
2706  if (enumerator.MoveNext())
2707  {
2708  TSource current;
2709  do
2710  {
2711  current = enumerator.Current;
2712  }
2713  while (enumerator.MoveNext());
2714  return current;
2715  }
2716  }
2717  }
2718  throw Error.NoElements();
2719  }
2720 
2729  [global::__DynamicallyInvokable]
2730  public static TSource Last<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2731  {
2732  if (source == null)
2733  {
2734  throw Error.ArgumentNull("source");
2735  }
2736  if (predicate == null)
2737  {
2738  throw Error.ArgumentNull("predicate");
2739  }
2740  TSource result = default(TSource);
2741  bool flag = false;
2742  foreach (TSource item in source)
2743  {
2744  if (predicate(item))
2745  {
2746  result = item;
2747  flag = true;
2748  }
2749  }
2750  if (flag)
2751  {
2752  return result;
2753  }
2754  throw Error.NoMatch();
2755  }
2756 
2764  [global::__DynamicallyInvokable]
2765  public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source)
2766  {
2767  if (source == null)
2768  {
2769  throw Error.ArgumentNull("source");
2770  }
2771  IList<TSource> list = source as IList<TSource>;
2772  if (list != null)
2773  {
2774  int count = list.Count;
2775  if (count > 0)
2776  {
2777  return list[count - 1];
2778  }
2779  }
2780  else
2781  {
2782  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2783  {
2784  if (enumerator.MoveNext())
2785  {
2786  TSource current;
2787  do
2788  {
2789  current = enumerator.Current;
2790  }
2791  while (enumerator.MoveNext());
2792  return current;
2793  }
2794  }
2795  }
2796  return default(TSource);
2797  }
2798 
2807  [global::__DynamicallyInvokable]
2808  public static TSource LastOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2809  {
2810  if (source == null)
2811  {
2812  throw Error.ArgumentNull("source");
2813  }
2814  if (predicate == null)
2815  {
2816  throw Error.ArgumentNull("predicate");
2817  }
2818  TSource result = default(TSource);
2819  foreach (TSource item in source)
2820  {
2821  if (predicate(item))
2822  {
2823  result = item;
2824  }
2825  }
2826  return result;
2827  }
2828 
2836  [global::__DynamicallyInvokable]
2837  public static TSource Single<TSource>(this IEnumerable<TSource> source)
2838  {
2839  if (source == null)
2840  {
2841  throw Error.ArgumentNull("source");
2842  }
2843  IList<TSource> list = source as IList<TSource>;
2844  if (list != null)
2845  {
2846  switch (list.Count)
2847  {
2848  case 0:
2849  throw Error.NoElements();
2850  case 1:
2851  return list[0];
2852  }
2853  }
2854  else
2855  {
2856  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2857  {
2858  if (!enumerator.MoveNext())
2859  {
2860  throw Error.NoElements();
2861  }
2862  TSource current = enumerator.Current;
2863  if (!enumerator.MoveNext())
2864  {
2865  return current;
2866  }
2867  }
2868  }
2869  throw Error.MoreThanOneElement();
2870  }
2871 
2880  [global::__DynamicallyInvokable]
2881  public static TSource Single<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2882  {
2883  if (source == null)
2884  {
2885  throw Error.ArgumentNull("source");
2886  }
2887  if (predicate == null)
2888  {
2889  throw Error.ArgumentNull("predicate");
2890  }
2891  TSource result = default(TSource);
2892  long num = 0L;
2893  foreach (TSource item in source)
2894  {
2895  if (predicate(item))
2896  {
2897  result = item;
2898  num = checked(num + 1);
2899  }
2900  }
2901  switch (num)
2902  {
2903  case 0L:
2904  throw Error.NoMatch();
2905  case 1L:
2906  return result;
2907  default:
2908  throw Error.MoreThanOneMatch();
2909  }
2910  }
2911 
2919  [global::__DynamicallyInvokable]
2920  public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source)
2921  {
2922  if (source == null)
2923  {
2924  throw Error.ArgumentNull("source");
2925  }
2926  IList<TSource> list = source as IList<TSource>;
2927  if (list != null)
2928  {
2929  switch (list.Count)
2930  {
2931  case 0:
2932  return default(TSource);
2933  case 1:
2934  return list[0];
2935  }
2936  }
2937  else
2938  {
2939  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
2940  {
2941  if (!enumerator.MoveNext())
2942  {
2943  return default(TSource);
2944  }
2945  TSource current = enumerator.Current;
2946  if (!enumerator.MoveNext())
2947  {
2948  return current;
2949  }
2950  }
2951  }
2952  throw Error.MoreThanOneElement();
2953  }
2954 
2962  [global::__DynamicallyInvokable]
2963  public static TSource SingleOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
2964  {
2965  if (source == null)
2966  {
2967  throw Error.ArgumentNull("source");
2968  }
2969  if (predicate == null)
2970  {
2971  throw Error.ArgumentNull("predicate");
2972  }
2973  TSource result = default(TSource);
2974  long num = 0L;
2975  foreach (TSource item in source)
2976  {
2977  if (predicate(item))
2978  {
2979  result = item;
2980  num = checked(num + 1);
2981  }
2982  }
2983  switch (num)
2984  {
2985  case 0L:
2986  return default(TSource);
2987  case 1L:
2988  return result;
2989  default:
2990  throw Error.MoreThanOneMatch();
2991  }
2992  }
2993 
3003  [global::__DynamicallyInvokable]
3004  public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index)
3005  {
3006  if (source == null)
3007  {
3008  throw Error.ArgumentNull("source");
3009  }
3010  IList<TSource> list = source as IList<TSource>;
3011  if (list != null)
3012  {
3013  return list[index];
3014  }
3015  if (index < 0)
3016  {
3017  throw Error.ArgumentOutOfRange("index");
3018  }
3019  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3020  {
3021  while (enumerator.MoveNext())
3022  {
3023  if (index == 0)
3024  {
3025  return enumerator.Current;
3026  }
3027  index--;
3028  }
3029  throw Error.ArgumentOutOfRange("index");
3030  }
3031  }
3032 
3041  [global::__DynamicallyInvokable]
3042  public static TSource ElementAtOrDefault<TSource>(this IEnumerable<TSource> source, int index)
3043  {
3044  if (source == null)
3045  {
3046  throw Error.ArgumentNull("source");
3047  }
3048  if (index >= 0)
3049  {
3050  IList<TSource> list = source as IList<TSource>;
3051  if (list != null)
3052  {
3053  if (index < list.Count)
3054  {
3055  return list[index];
3056  }
3057  }
3058  else
3059  {
3060  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3061  {
3062  while (enumerator.MoveNext())
3063  {
3064  if (index == 0)
3065  {
3066  return enumerator.Current;
3067  }
3068  index--;
3069  }
3070  }
3071  }
3072  }
3073  return default(TSource);
3074  }
3075 
3083  [global::__DynamicallyInvokable]
3084  public static IEnumerable<int> Range(int start, int count)
3085  {
3086  long num = (long)start + (long)count - 1;
3087  if (count < 0 || num > int.MaxValue)
3088  {
3089  throw Error.ArgumentOutOfRange("count");
3090  }
3091  return RangeIterator(start, count);
3092  }
3093 
3094  private static IEnumerable<int> RangeIterator(int start, int count)
3095  {
3096  for (int i = 0; i < count; i++)
3097  {
3098  yield return start + i;
3099  }
3100  }
3101 
3109  [global::__DynamicallyInvokable]
3110  public static IEnumerable<TResult> Repeat<TResult>(TResult element, int count)
3111  {
3112  if (count < 0)
3113  {
3114  throw Error.ArgumentOutOfRange("count");
3115  }
3116  return RepeatIterator(element, count);
3117  }
3118 
3119  private static IEnumerable<TResult> RepeatIterator<TResult>(TResult element, int count)
3120  {
3121  for (int i = 0; i < count; i++)
3122  {
3123  yield return element;
3124  }
3125  }
3126 
3130  [global::__DynamicallyInvokable]
3132  {
3133  return EmptyEnumerable<TResult>.Instance;
3134  }
3135 
3143  [global::__DynamicallyInvokable]
3144  public static bool Any<TSource>(this IEnumerable<TSource> source)
3145  {
3146  if (source == null)
3147  {
3148  throw Error.ArgumentNull("source");
3149  }
3150  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3151  {
3152  if (enumerator.MoveNext())
3153  {
3154  return true;
3155  }
3156  }
3157  return false;
3158  }
3159 
3168  [global::__DynamicallyInvokable]
3169  public static bool Any<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
3170  {
3171  if (source == null)
3172  {
3173  throw Error.ArgumentNull("source");
3174  }
3175  if (predicate == null)
3176  {
3177  throw Error.ArgumentNull("predicate");
3178  }
3179  foreach (TSource item in source)
3180  {
3181  if (predicate(item))
3182  {
3183  return true;
3184  }
3185  }
3186  return false;
3187  }
3188 
3197  [global::__DynamicallyInvokable]
3198  public static bool All<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
3199  {
3200  if (source == null)
3201  {
3202  throw Error.ArgumentNull("source");
3203  }
3204  if (predicate == null)
3205  {
3206  throw Error.ArgumentNull("predicate");
3207  }
3208  foreach (TSource item in source)
3209  {
3210  if (!predicate(item))
3211  {
3212  return false;
3213  }
3214  }
3215  return true;
3216  }
3217 
3225  [global::__DynamicallyInvokable]
3226  public static int Count<TSource>(this IEnumerable<TSource> source)
3227  {
3228  if (source == null)
3229  {
3230  throw Error.ArgumentNull("source");
3231  }
3232  ICollection<TSource> collection = source as ICollection<TSource>;
3233  if (collection != null)
3234  {
3235  return collection.Count;
3236  }
3237  ICollection collection2 = source as ICollection;
3238  if (collection2 != null)
3239  {
3240  return collection2.Count;
3241  }
3242  int num = 0;
3243  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3244  {
3245  while (enumerator.MoveNext())
3246  {
3247  num = checked(num + 1);
3248  }
3249  return num;
3250  }
3251  }
3252 
3261  [global::__DynamicallyInvokable]
3262  public static int Count<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
3263  {
3264  if (source == null)
3265  {
3266  throw Error.ArgumentNull("source");
3267  }
3268  if (predicate == null)
3269  {
3270  throw Error.ArgumentNull("predicate");
3271  }
3272  int num = 0;
3273  foreach (TSource item in source)
3274  {
3275  if (predicate(item))
3276  {
3277  num = checked(num + 1);
3278  }
3279  }
3280  return num;
3281  }
3282 
3290  [global::__DynamicallyInvokable]
3291  public static long LongCount<TSource>(this IEnumerable<TSource> source)
3292  {
3293  if (source == null)
3294  {
3295  throw Error.ArgumentNull("source");
3296  }
3297  long num = 0L;
3298  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3299  {
3300  while (enumerator.MoveNext())
3301  {
3302  num = checked(num + 1);
3303  }
3304  return num;
3305  }
3306  }
3307 
3316  [global::__DynamicallyInvokable]
3317  public static long LongCount<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
3318  {
3319  if (source == null)
3320  {
3321  throw Error.ArgumentNull("source");
3322  }
3323  if (predicate == null)
3324  {
3325  throw Error.ArgumentNull("predicate");
3326  }
3327  long num = 0L;
3328  foreach (TSource item in source)
3329  {
3330  if (predicate(item))
3331  {
3332  num = checked(num + 1);
3333  }
3334  }
3335  return num;
3336  }
3337 
3346  [global::__DynamicallyInvokable]
3347  public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value)
3348  {
3349  return (source as ICollection<TSource>)?.Contains(value) ?? source.Contains(value, null);
3350  }
3351 
3361  [global::__DynamicallyInvokable]
3362  public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
3363  {
3364  if (comparer == null)
3365  {
3367  }
3368  if (source == null)
3369  {
3370  throw Error.ArgumentNull("source");
3371  }
3372  foreach (TSource item in source)
3373  {
3374  if (comparer.Equals(item, value))
3375  {
3376  return true;
3377  }
3378  }
3379  return false;
3380  }
3381 
3391  [global::__DynamicallyInvokable]
3392  public static TSource Aggregate<TSource>(this IEnumerable<TSource> source, Func<TSource, TSource, TSource> func)
3393  {
3394  if (source == null)
3395  {
3396  throw Error.ArgumentNull("source");
3397  }
3398  if (func == null)
3399  {
3400  throw Error.ArgumentNull("func");
3401  }
3402  using (IEnumerator<TSource> enumerator = source.GetEnumerator())
3403  {
3404  if (!enumerator.MoveNext())
3405  {
3406  throw Error.NoElements();
3407  }
3408  TSource val = enumerator.Current;
3409  while (enumerator.MoveNext())
3410  {
3411  val = func(val, enumerator.Current);
3412  }
3413  return val;
3414  }
3415  }
3416 
3426  [global::__DynamicallyInvokable]
3427  public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func)
3428  {
3429  if (source == null)
3430  {
3431  throw Error.ArgumentNull("source");
3432  }
3433  if (func == null)
3434  {
3435  throw Error.ArgumentNull("func");
3436  }
3437  TAccumulate val = seed;
3438  foreach (TSource item in source)
3439  {
3440  val = func(val, item);
3441  }
3442  return val;
3443  }
3444 
3456  [global::__DynamicallyInvokable]
3457  public static TResult Aggregate<TSource, TAccumulate, TResult>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector)
3458  {
3459  if (source == null)
3460  {
3461  throw Error.ArgumentNull("source");
3462  }
3463  if (func == null)
3464  {
3465  throw Error.ArgumentNull("func");
3466  }
3467  if (resultSelector == null)
3468  {
3469  throw Error.ArgumentNull("resultSelector");
3470  }
3471  TAccumulate val = seed;
3472  foreach (TSource item in source)
3473  {
3474  val = func(val, item);
3475  }
3476  return resultSelector(val);
3477  }
3478 
3485  [global::__DynamicallyInvokable]
3486  public static int Sum(this IEnumerable<int> source)
3487  {
3488  if (source == null)
3489  {
3490  throw Error.ArgumentNull("source");
3491  }
3492  int num = 0;
3493  foreach (int item in source)
3494  {
3495  num = checked(num + item);
3496  }
3497  return num;
3498  }
3499 
3506  [global::__DynamicallyInvokable]
3507  public static int? Sum(this IEnumerable<int?> source)
3508  {
3509  if (source == null)
3510  {
3511  throw Error.ArgumentNull("source");
3512  }
3513  int num = 0;
3514  foreach (int? item in source)
3515  {
3516  if (item.HasValue)
3517  {
3518  num = checked(num + item.GetValueOrDefault());
3519  }
3520  }
3521  return num;
3522  }
3523 
3530  [global::__DynamicallyInvokable]
3531  public static long Sum(this IEnumerable<long> source)
3532  {
3533  if (source == null)
3534  {
3535  throw Error.ArgumentNull("source");
3536  }
3537  long num = 0L;
3538  foreach (long item in source)
3539  {
3540  num = checked(num + item);
3541  }
3542  return num;
3543  }
3544 
3551  [global::__DynamicallyInvokable]
3552  public static long? Sum(this IEnumerable<long?> source)
3553  {
3554  if (source == null)
3555  {
3556  throw Error.ArgumentNull("source");
3557  }
3558  long num = 0L;
3559  foreach (long? item in source)
3560  {
3561  if (item.HasValue)
3562  {
3563  num = checked(num + item.GetValueOrDefault());
3564  }
3565  }
3566  return num;
3567  }
3568 
3574  [global::__DynamicallyInvokable]
3575  public static float Sum(this IEnumerable<float> source)
3576  {
3577  if (source == null)
3578  {
3579  throw Error.ArgumentNull("source");
3580  }
3581  double num = 0.0;
3582  foreach (float item in source)
3583  {
3584  num += (double)item;
3585  }
3586  return (float)num;
3587  }
3588 
3594  [global::__DynamicallyInvokable]
3595  public static float? Sum(this IEnumerable<float?> source)
3596  {
3597  if (source == null)
3598  {
3599  throw Error.ArgumentNull("source");
3600  }
3601  double num = 0.0;
3602  foreach (float? item in source)
3603  {
3604  if (item.HasValue)
3605  {
3606  num += (double)item.GetValueOrDefault();
3607  }
3608  }
3609  return (float)num;
3610  }
3611 
3617  [global::__DynamicallyInvokable]
3618  public static double Sum(this IEnumerable<double> source)
3619  {
3620  if (source == null)
3621  {
3622  throw Error.ArgumentNull("source");
3623  }
3624  double num = 0.0;
3625  foreach (double item in source)
3626  {
3627  num += item;
3628  }
3629  return num;
3630  }
3631 
3637  [global::__DynamicallyInvokable]
3638  public static double? Sum(this IEnumerable<double?> source)
3639  {
3640  if (source == null)
3641  {
3642  throw Error.ArgumentNull("source");
3643  }
3644  double num = 0.0;
3645  foreach (double? item in source)
3646  {
3647  if (item.HasValue)
3648  {
3649  num += item.GetValueOrDefault();
3650  }
3651  }
3652  return num;
3653  }
3654 
3661  [global::__DynamicallyInvokable]
3662  public static decimal Sum(this IEnumerable<decimal> source)
3663  {
3664  if (source == null)
3665  {
3666  throw Error.ArgumentNull("source");
3667  }
3668  decimal num = default(decimal);
3669  foreach (decimal item in source)
3670  {
3671  num += item;
3672  }
3673  return num;
3674  }
3675 
3682  [global::__DynamicallyInvokable]
3683  public static decimal? Sum(this IEnumerable<decimal?> source)
3684  {
3685  if (source == null)
3686  {
3687  throw Error.ArgumentNull("source");
3688  }
3689  decimal num = default(decimal);
3690  foreach (decimal? item in source)
3691  {
3692  if (item.HasValue)
3693  {
3694  num += item.GetValueOrDefault();
3695  }
3696  }
3697  return num;
3698  }
3699 
3708  [global::__DynamicallyInvokable]
3709  public static int Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
3710  {
3711  return source.Select(selector).Sum();
3712  }
3713 
3722  [global::__DynamicallyInvokable]
3723  public static int? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector)
3724  {
3725  return source.Select(selector).Sum();
3726  }
3727 
3736  [global::__DynamicallyInvokable]
3737  public static long Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
3738  {
3739  return source.Select(selector).Sum();
3740  }
3741 
3750  [global::__DynamicallyInvokable]
3751  public static long? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector)
3752  {
3753  return source.Select(selector).Sum();
3754  }
3755 
3763  [global::__DynamicallyInvokable]
3764  public static float Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
3765  {
3766  return source.Select(selector).Sum();
3767  }
3768 
3776  [global::__DynamicallyInvokable]
3777  public static float? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector)
3778  {
3779  return source.Select(selector).Sum();
3780  }
3781 
3789  [global::__DynamicallyInvokable]
3790  public static double Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
3791  {
3792  return source.Select(selector).Sum();
3793  }
3794 
3802  [global::__DynamicallyInvokable]
3803  public static double? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
3804  {
3805  return source.Select(selector).Sum();
3806  }
3807 
3816  [global::__DynamicallyInvokable]
3817  public static decimal Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
3818  {
3819  return source.Select(selector).Sum();
3820  }
3821 
3830  [global::__DynamicallyInvokable]
3831  public static decimal? Sum<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
3832  {
3833  return source.Select(selector).Sum();
3834  }
3835 
3843  [global::__DynamicallyInvokable]
3844  public static int Min(this IEnumerable<int> source)
3845  {
3846  if (source == null)
3847  {
3848  throw Error.ArgumentNull("source");
3849  }
3850  int num = 0;
3851  bool flag = false;
3852  foreach (int item in source)
3853  {
3854  if (flag)
3855  {
3856  if (item < num)
3857  {
3858  num = item;
3859  }
3860  }
3861  else
3862  {
3863  num = item;
3864  flag = true;
3865  }
3866  }
3867  if (flag)
3868  {
3869  return num;
3870  }
3871  throw Error.NoElements();
3872  }
3873 
3879  [global::__DynamicallyInvokable]
3880  public static int? Min(this IEnumerable<int?> source)
3881  {
3882  if (source == null)
3883  {
3884  throw Error.ArgumentNull("source");
3885  }
3886  int? num = null;
3887  foreach (int? item in source)
3888  {
3889  if (!num.HasValue || item < num)
3890  {
3891  num = item;
3892  }
3893  }
3894  return num;
3895  }
3896 
3904  [global::__DynamicallyInvokable]
3905  public static long Min(this IEnumerable<long> source)
3906  {
3907  if (source == null)
3908  {
3909  throw Error.ArgumentNull("source");
3910  }
3911  long num = 0L;
3912  bool flag = false;
3913  foreach (long item in source)
3914  {
3915  if (flag)
3916  {
3917  if (item < num)
3918  {
3919  num = item;
3920  }
3921  }
3922  else
3923  {
3924  num = item;
3925  flag = true;
3926  }
3927  }
3928  if (flag)
3929  {
3930  return num;
3931  }
3932  throw Error.NoElements();
3933  }
3934 
3940  [global::__DynamicallyInvokable]
3941  public static long? Min(this IEnumerable<long?> source)
3942  {
3943  if (source == null)
3944  {
3945  throw Error.ArgumentNull("source");
3946  }
3947  long? num = null;
3948  foreach (long? item in source)
3949  {
3950  if (!num.HasValue || item < num)
3951  {
3952  num = item;
3953  }
3954  }
3955  return num;
3956  }
3957 
3965  [global::__DynamicallyInvokable]
3966  public static float Min(this IEnumerable<float> source)
3967  {
3968  if (source == null)
3969  {
3970  throw Error.ArgumentNull("source");
3971  }
3972  float num = 0f;
3973  bool flag = false;
3974  foreach (float item in source)
3975  {
3976  if (flag)
3977  {
3978  if (item < num || float.IsNaN(item))
3979  {
3980  num = item;
3981  }
3982  }
3983  else
3984  {
3985  num = item;
3986  flag = true;
3987  }
3988  }
3989  if (flag)
3990  {
3991  return num;
3992  }
3993  throw Error.NoElements();
3994  }
3995 
4001  [global::__DynamicallyInvokable]
4002  public static float? Min(this IEnumerable<float?> source)
4003  {
4004  if (source == null)
4005  {
4006  throw Error.ArgumentNull("source");
4007  }
4008  float? num = null;
4009  foreach (float? item in source)
4010  {
4011  if (item.HasValue && (!num.HasValue || item < num || float.IsNaN(item.Value)))
4012  {
4013  num = item;
4014  }
4015  }
4016  return num;
4017  }
4018 
4026  [global::__DynamicallyInvokable]
4027  public static double Min(this IEnumerable<double> source)
4028  {
4029  if (source == null)
4030  {
4031  throw Error.ArgumentNull("source");
4032  }
4033  double num = 0.0;
4034  bool flag = false;
4035  foreach (double item in source)
4036  {
4037  if (flag)
4038  {
4039  if (item < num || double.IsNaN(item))
4040  {
4041  num = item;
4042  }
4043  }
4044  else
4045  {
4046  num = item;
4047  flag = true;
4048  }
4049  }
4050  if (flag)
4051  {
4052  return num;
4053  }
4054  throw Error.NoElements();
4055  }
4056 
4062  [global::__DynamicallyInvokable]
4063  public static double? Min(this IEnumerable<double?> source)
4064  {
4065  if (source == null)
4066  {
4067  throw Error.ArgumentNull("source");
4068  }
4069  double? num = null;
4070  foreach (double? item in source)
4071  {
4072  if (item.HasValue && (!num.HasValue || item < num || double.IsNaN(item.Value)))
4073  {
4074  num = item;
4075  }
4076  }
4077  return num;
4078  }
4079 
4087  [global::__DynamicallyInvokable]
4088  public static decimal Min(this IEnumerable<decimal> source)
4089  {
4090  if (source == null)
4091  {
4092  throw Error.ArgumentNull("source");
4093  }
4094  decimal num = default(decimal);
4095  bool flag = false;
4096  foreach (decimal item in source)
4097  {
4098  if (flag)
4099  {
4100  if (item < num)
4101  {
4102  num = item;
4103  }
4104  }
4105  else
4106  {
4107  num = item;
4108  flag = true;
4109  }
4110  }
4111  if (flag)
4112  {
4113  return num;
4114  }
4115  throw Error.NoElements();
4116  }
4117 
4123  [global::__DynamicallyInvokable]
4124  public static decimal? Min(this IEnumerable<decimal?> source)
4125  {
4126  if (source == null)
4127  {
4128  throw Error.ArgumentNull("source");
4129  }
4130  decimal? num = null;
4131  foreach (decimal? item in source)
4132  {
4133  if (!num.HasValue || item < num)
4134  {
4135  num = item;
4136  }
4137  }
4138  return num;
4139  }
4140 
4147  [global::__DynamicallyInvokable]
4148  public static TSource Min<TSource>(this IEnumerable<TSource> source)
4149  {
4150  if (source == null)
4151  {
4152  throw Error.ArgumentNull("source");
4153  }
4155  TSource val = default(TSource);
4156  if (val == null)
4157  {
4158  foreach (TSource item in source)
4159  {
4160  if (item != null && (val == null || @default.Compare(item, val) < 0))
4161  {
4162  val = item;
4163  }
4164  }
4165  return val;
4166  }
4167  bool flag = false;
4168  foreach (TSource item2 in source)
4169  {
4170  if (flag)
4171  {
4172  if (@default.Compare(item2, val) < 0)
4173  {
4174  val = item2;
4175  }
4176  }
4177  else
4178  {
4179  val = item2;
4180  flag = true;
4181  }
4182  }
4183  if (flag)
4184  {
4185  return val;
4186  }
4187  throw Error.NoElements();
4188  }
4189 
4199  [global::__DynamicallyInvokable]
4200  public static int Min<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
4201  {
4202  return source.Select(selector).Min();
4203  }
4204 
4212  [global::__DynamicallyInvokable]
4213  public static int? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector)
4214  {
4215  return source.Select(selector).Min();
4216  }
4217 
4227  [global::__DynamicallyInvokable]
4228  public static long Min<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
4229  {
4230  return source.Select(selector).Min();
4231  }
4232 
4240  [global::__DynamicallyInvokable]
4241  public static long? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector)
4242  {
4243  return source.Select(selector).Min();
4244  }
4245 
4255  [global::__DynamicallyInvokable]
4256  public static float Min<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
4257  {
4258  return source.Select(selector).Min();
4259  }
4260 
4268  [global::__DynamicallyInvokable]
4269  public static float? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector)
4270  {
4271  return source.Select(selector).Min();
4272  }
4273 
4283  [global::__DynamicallyInvokable]
4284  public static double Min<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
4285  {
4286  return source.Select(selector).Min();
4287  }
4288 
4296  [global::__DynamicallyInvokable]
4297  public static double? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
4298  {
4299  return source.Select(selector).Min();
4300  }
4301 
4311  [global::__DynamicallyInvokable]
4312  public static decimal Min<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
4313  {
4314  return source.Select(selector).Min();
4315  }
4316 
4324  [global::__DynamicallyInvokable]
4325  public static decimal? Min<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
4326  {
4327  return source.Select(selector).Min();
4328  }
4329 
4338  [global::__DynamicallyInvokable]
4339  public static TResult Min<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
4340  {
4341  return source.Select(selector).Min();
4342  }
4343 
4351  [global::__DynamicallyInvokable]
4352  public static int Max(this IEnumerable<int> source)
4353  {
4354  if (source == null)
4355  {
4356  throw Error.ArgumentNull("source");
4357  }
4358  int num = 0;
4359  bool flag = false;
4360  foreach (int item in source)
4361  {
4362  if (flag)
4363  {
4364  if (item > num)
4365  {
4366  num = item;
4367  }
4368  }
4369  else
4370  {
4371  num = item;
4372  flag = true;
4373  }
4374  }
4375  if (flag)
4376  {
4377  return num;
4378  }
4379  throw Error.NoElements();
4380  }
4381 
4387  [global::__DynamicallyInvokable]
4388  public static int? Max(this IEnumerable<int?> source)
4389  {
4390  if (source == null)
4391  {
4392  throw Error.ArgumentNull("source");
4393  }
4394  int? num = null;
4395  foreach (int? item in source)
4396  {
4397  if (!num.HasValue || item > num)
4398  {
4399  num = item;
4400  }
4401  }
4402  return num;
4403  }
4404 
4412  [global::__DynamicallyInvokable]
4413  public static long Max(this IEnumerable<long> source)
4414  {
4415  if (source == null)
4416  {
4417  throw Error.ArgumentNull("source");
4418  }
4419  long num = 0L;
4420  bool flag = false;
4421  foreach (long item in source)
4422  {
4423  if (flag)
4424  {
4425  if (item > num)
4426  {
4427  num = item;
4428  }
4429  }
4430  else
4431  {
4432  num = item;
4433  flag = true;
4434  }
4435  }
4436  if (flag)
4437  {
4438  return num;
4439  }
4440  throw Error.NoElements();
4441  }
4442 
4448  [global::__DynamicallyInvokable]
4449  public static long? Max(this IEnumerable<long?> source)
4450  {
4451  if (source == null)
4452  {
4453  throw Error.ArgumentNull("source");
4454  }
4455  long? num = null;
4456  foreach (long? item in source)
4457  {
4458  if (!num.HasValue || item > num)
4459  {
4460  num = item;
4461  }
4462  }
4463  return num;
4464  }
4465 
4473  [global::__DynamicallyInvokable]
4474  public static double Max(this IEnumerable<double> source)
4475  {
4476  if (source == null)
4477  {
4478  throw Error.ArgumentNull("source");
4479  }
4480  double num = 0.0;
4481  bool flag = false;
4482  foreach (double item in source)
4483  {
4484  if (flag)
4485  {
4486  if (item > num || double.IsNaN(num))
4487  {
4488  num = item;
4489  }
4490  }
4491  else
4492  {
4493  num = item;
4494  flag = true;
4495  }
4496  }
4497  if (flag)
4498  {
4499  return num;
4500  }
4501  throw Error.NoElements();
4502  }
4503 
4509  [global::__DynamicallyInvokable]
4510  public static double? Max(this IEnumerable<double?> source)
4511  {
4512  if (source == null)
4513  {
4514  throw Error.ArgumentNull("source");
4515  }
4516  double? num = null;
4517  foreach (double? item in source)
4518  {
4519  if (item.HasValue && (!num.HasValue || item > num || double.IsNaN(num.Value)))
4520  {
4521  num = item;
4522  }
4523  }
4524  return num;
4525  }
4526 
4534  [global::__DynamicallyInvokable]
4535  public static float Max(this IEnumerable<float> source)
4536  {
4537  if (source == null)
4538  {
4539  throw Error.ArgumentNull("source");
4540  }
4541  float num = 0f;
4542  bool flag = false;
4543  foreach (float item in source)
4544  {
4545  if (flag)
4546  {
4547  if (item > num || double.IsNaN(num))
4548  {
4549  num = item;
4550  }
4551  }
4552  else
4553  {
4554  num = item;
4555  flag = true;
4556  }
4557  }
4558  if (flag)
4559  {
4560  return num;
4561  }
4562  throw Error.NoElements();
4563  }
4564 
4570  [global::__DynamicallyInvokable]
4571  public static float? Max(this IEnumerable<float?> source)
4572  {
4573  if (source == null)
4574  {
4575  throw Error.ArgumentNull("source");
4576  }
4577  float? num = null;
4578  foreach (float? item in source)
4579  {
4580  if (item.HasValue && (!num.HasValue || item > num || float.IsNaN(num.Value)))
4581  {
4582  num = item;
4583  }
4584  }
4585  return num;
4586  }
4587 
4595  [global::__DynamicallyInvokable]
4596  public static decimal Max(this IEnumerable<decimal> source)
4597  {
4598  if (source == null)
4599  {
4600  throw Error.ArgumentNull("source");
4601  }
4602  decimal num = default(decimal);
4603  bool flag = false;
4604  foreach (decimal item in source)
4605  {
4606  if (flag)
4607  {
4608  if (item > num)
4609  {
4610  num = item;
4611  }
4612  }
4613  else
4614  {
4615  num = item;
4616  flag = true;
4617  }
4618  }
4619  if (flag)
4620  {
4621  return num;
4622  }
4623  throw Error.NoElements();
4624  }
4625 
4631  [global::__DynamicallyInvokable]
4632  public static decimal? Max(this IEnumerable<decimal?> source)
4633  {
4634  if (source == null)
4635  {
4636  throw Error.ArgumentNull("source");
4637  }
4638  decimal? num = null;
4639  foreach (decimal? item in source)
4640  {
4641  if (!num.HasValue || item > num)
4642  {
4643  num = item;
4644  }
4645  }
4646  return num;
4647  }
4648 
4655  [global::__DynamicallyInvokable]
4656  public static TSource Max<TSource>(this IEnumerable<TSource> source)
4657  {
4658  if (source == null)
4659  {
4660  throw Error.ArgumentNull("source");
4661  }
4663  TSource val = default(TSource);
4664  if (val == null)
4665  {
4666  foreach (TSource item in source)
4667  {
4668  if (item != null && (val == null || @default.Compare(item, val) > 0))
4669  {
4670  val = item;
4671  }
4672  }
4673  return val;
4674  }
4675  bool flag = false;
4676  foreach (TSource item2 in source)
4677  {
4678  if (flag)
4679  {
4680  if (@default.Compare(item2, val) > 0)
4681  {
4682  val = item2;
4683  }
4684  }
4685  else
4686  {
4687  val = item2;
4688  flag = true;
4689  }
4690  }
4691  if (flag)
4692  {
4693  return val;
4694  }
4695  throw Error.NoElements();
4696  }
4697 
4707  [global::__DynamicallyInvokable]
4708  public static int Max<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
4709  {
4710  return source.Select(selector).Max();
4711  }
4712 
4720  [global::__DynamicallyInvokable]
4721  public static int? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector)
4722  {
4723  return source.Select(selector).Max();
4724  }
4725 
4735  [global::__DynamicallyInvokable]
4736  public static long Max<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
4737  {
4738  return source.Select(selector).Max();
4739  }
4740 
4748  [global::__DynamicallyInvokable]
4749  public static long? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector)
4750  {
4751  return source.Select(selector).Max();
4752  }
4753 
4763  [global::__DynamicallyInvokable]
4764  public static float Max<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
4765  {
4766  return source.Select(selector).Max();
4767  }
4768 
4776  [global::__DynamicallyInvokable]
4777  public static float? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector)
4778  {
4779  return source.Select(selector).Max();
4780  }
4781 
4791  [global::__DynamicallyInvokable]
4792  public static double Max<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
4793  {
4794  return source.Select(selector).Max();
4795  }
4796 
4804  [global::__DynamicallyInvokable]
4805  public static double? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
4806  {
4807  return source.Select(selector).Max();
4808  }
4809 
4819  [global::__DynamicallyInvokable]
4820  public static decimal Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
4821  {
4822  return source.Select(selector).Max();
4823  }
4824 
4832  [global::__DynamicallyInvokable]
4833  public static decimal? Max<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
4834  {
4835  return source.Select(selector).Max();
4836  }
4837 
4846  [global::__DynamicallyInvokable]
4847  public static TResult Max<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
4848  {
4849  return source.Select(selector).Max();
4850  }
4851 
4859  [global::__DynamicallyInvokable]
4860  public static double Average(this IEnumerable<int> source)
4861  {
4862  if (source == null)
4863  {
4864  throw Error.ArgumentNull("source");
4865  }
4866  long num = 0L;
4867  long num2 = 0L;
4868  checked
4869  {
4870  foreach (int item in source)
4871  {
4872  num += item;
4873  num2++;
4874  }
4875  }
4876  if (num2 > 0)
4877  {
4878  return (double)num / (double)num2;
4879  }
4880  throw Error.NoElements();
4881  }
4882 
4889  [global::__DynamicallyInvokable]
4890  public static double? Average(this IEnumerable<int?> source)
4891  {
4892  if (source == null)
4893  {
4894  throw Error.ArgumentNull("source");
4895  }
4896  long num = 0L;
4897  long num2 = 0L;
4898  checked
4899  {
4900  foreach (int? item in source)
4901  {
4902  if (item.HasValue)
4903  {
4904  num += item.GetValueOrDefault();
4905  num2++;
4906  }
4907  }
4908  }
4909  if (num2 > 0)
4910  {
4911  return (double)num / (double)num2;
4912  }
4913  return null;
4914  }
4915 
4923  [global::__DynamicallyInvokable]
4924  public static double Average(this IEnumerable<long> source)
4925  {
4926  if (source == null)
4927  {
4928  throw Error.ArgumentNull("source");
4929  }
4930  long num = 0L;
4931  long num2 = 0L;
4932  checked
4933  {
4934  foreach (long item in source)
4935  {
4936  num += item;
4937  num2++;
4938  }
4939  }
4940  if (num2 > 0)
4941  {
4942  return (double)num / (double)num2;
4943  }
4944  throw Error.NoElements();
4945  }
4946 
4953  [global::__DynamicallyInvokable]
4954  public static double? Average(this IEnumerable<long?> source)
4955  {
4956  if (source == null)
4957  {
4958  throw Error.ArgumentNull("source");
4959  }
4960  long num = 0L;
4961  long num2 = 0L;
4962  checked
4963  {
4964  foreach (long? item in source)
4965  {
4966  if (item.HasValue)
4967  {
4968  num += item.GetValueOrDefault();
4969  num2++;
4970  }
4971  }
4972  }
4973  if (num2 > 0)
4974  {
4975  return (double)num / (double)num2;
4976  }
4977  return null;
4978  }
4979 
4987  [global::__DynamicallyInvokable]
4988  public static float Average(this IEnumerable<float> source)
4989  {
4990  if (source == null)
4991  {
4992  throw Error.ArgumentNull("source");
4993  }
4994  double num = 0.0;
4995  long num2 = 0L;
4996  foreach (float item in source)
4997  {
4998  num += (double)item;
4999  num2 = checked(num2 + 1);
5000  }
5001  if (num2 > 0)
5002  {
5003  return (float)(num / (double)num2);
5004  }
5005  throw Error.NoElements();
5006  }
5007 
5013  [global::__DynamicallyInvokable]
5014  public static float? Average(this IEnumerable<float?> source)
5015  {
5016  if (source == null)
5017  {
5018  throw Error.ArgumentNull("source");
5019  }
5020  double num = 0.0;
5021  long num2 = 0L;
5022  foreach (float? item in source)
5023  {
5024  if (item.HasValue)
5025  {
5026  num += (double)item.GetValueOrDefault();
5027  num2 = checked(num2 + 1);
5028  }
5029  }
5030  if (num2 > 0)
5031  {
5032  return (float)(num / (double)num2);
5033  }
5034  return null;
5035  }
5036 
5044  [global::__DynamicallyInvokable]
5045  public static double Average(this IEnumerable<double> source)
5046  {
5047  if (source == null)
5048  {
5049  throw Error.ArgumentNull("source");
5050  }
5051  double num = 0.0;
5052  long num2 = 0L;
5053  foreach (double item in source)
5054  {
5055  num += item;
5056  num2 = checked(num2 + 1);
5057  }
5058  if (num2 > 0)
5059  {
5060  return num / (double)num2;
5061  }
5062  throw Error.NoElements();
5063  }
5064 
5070  [global::__DynamicallyInvokable]
5071  public static double? Average(this IEnumerable<double?> source)
5072  {
5073  if (source == null)
5074  {
5075  throw Error.ArgumentNull("source");
5076  }
5077  double num = 0.0;
5078  long num2 = 0L;
5079  foreach (double? item in source)
5080  {
5081  if (item.HasValue)
5082  {
5083  num += item.GetValueOrDefault();
5084  num2 = checked(num2 + 1);
5085  }
5086  }
5087  if (num2 > 0)
5088  {
5089  return num / (double)num2;
5090  }
5091  return null;
5092  }
5093 
5101  [global::__DynamicallyInvokable]
5102  public static decimal Average(this IEnumerable<decimal> source)
5103  {
5104  if (source == null)
5105  {
5106  throw Error.ArgumentNull("source");
5107  }
5108  decimal d = default(decimal);
5109  long num = 0L;
5110  foreach (decimal item in source)
5111  {
5112  d += item;
5113  num = checked(num + 1);
5114  }
5115  if (num > 0)
5116  {
5117  return d / (decimal)num;
5118  }
5119  throw Error.NoElements();
5120  }
5121 
5128  [global::__DynamicallyInvokable]
5129  public static decimal? Average(this IEnumerable<decimal?> source)
5130  {
5131  if (source == null)
5132  {
5133  throw Error.ArgumentNull("source");
5134  }
5135  decimal d = default(decimal);
5136  long num = 0L;
5137  foreach (decimal? item in source)
5138  {
5139  if (item.HasValue)
5140  {
5141  d += item.GetValueOrDefault();
5142  num = checked(num + 1);
5143  }
5144  }
5145  if (num > 0)
5146  {
5147  return d / (decimal)num;
5148  }
5149  return null;
5150  }
5151 
5162  [global::__DynamicallyInvokable]
5163  public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int> selector)
5164  {
5165  return source.Select(selector).Average();
5166  }
5167 
5176  [global::__DynamicallyInvokable]
5177  public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, int?> selector)
5178  {
5179  return source.Select(selector).Average();
5180  }
5181 
5192  [global::__DynamicallyInvokable]
5193  public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long> selector)
5194  {
5195  return source.Select(selector).Average();
5196  }
5197 
5203  [global::__DynamicallyInvokable]
5204  public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, long?> selector)
5205  {
5206  return source.Select(selector).Average();
5207  }
5208 
5218  [global::__DynamicallyInvokable]
5219  public static float Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float> selector)
5220  {
5221  return source.Select(selector).Average();
5222  }
5223 
5231  [global::__DynamicallyInvokable]
5232  public static float? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, float?> selector)
5233  {
5234  return source.Select(selector).Average();
5235  }
5236 
5246  [global::__DynamicallyInvokable]
5247  public static double Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double> selector)
5248  {
5249  return source.Select(selector).Average();
5250  }
5251 
5259  [global::__DynamicallyInvokable]
5260  public static double? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, double?> selector)
5261  {
5262  return source.Select(selector).Average();
5263  }
5264 
5275  [global::__DynamicallyInvokable]
5276  public static decimal Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal> selector)
5277  {
5278  return source.Select(selector).Average();
5279  }
5280 
5289  [global::__DynamicallyInvokable]
5290  public static decimal? Average<TSource>(this IEnumerable<TSource> source, Func<TSource, decimal?> selector)
5291  {
5292  return source.Select(selector).Average();
5293  }
5294 
5302  public static IEnumerable<TSource> Append<TSource>(this IEnumerable<TSource> source, TSource element)
5303  {
5304  if (source == null)
5305  {
5306  throw Error.ArgumentNull("source");
5307  }
5308  AppendPrependIterator<TSource> appendPrependIterator = source as AppendPrependIterator<TSource>;
5309  if (appendPrependIterator != null)
5310  {
5311  return appendPrependIterator.Append(element);
5312  }
5313  return new AppendPrepend1Iterator<TSource>(source, element, appending: true);
5314  }
5315 
5323  public static IEnumerable<TSource> Prepend<TSource>(this IEnumerable<TSource> source, TSource element)
5324  {
5325  if (source == null)
5326  {
5327  throw Error.ArgumentNull("source");
5328  }
5329  AppendPrependIterator<TSource> appendPrependIterator = source as AppendPrependIterator<TSource>;
5330  if (appendPrependIterator != null)
5331  {
5332  return appendPrependIterator.Prepend(element);
5333  }
5334  return new AppendPrepend1Iterator<TSource>(source, element, appending: false);
5335  }
5336  }
5337 }
static Thread CurrentThread
Gets the currently running thread.
Definition: Thread.cs:134
static ? long Max(this IEnumerable< long?> source)
Returns the maximum value in a sequence of nullable T:System.Int64 values.
Definition: Enumerable.cs:4449
static IEnumerable< TSource > Append< TSource >(this IEnumerable< TSource > source, TSource element)
Appends a value to the end of the sequence.
Definition: Enumerable.cs:5302
static TSource [] ToArray< TSource >(this IEnumerable< TSource > source)
Creates an array from a T:System.Collections.Generic.IEnumerable`1.
Definition: Enumerable.cs:2270
Compares two objects for equivalence, where string comparisons are case-sensitive.
Definition: Comparer.cs:11
static IEnumerable< TResult > OfType< TResult >(this IEnumerable source)
Filters the elements of an T:System.Collections.IEnumerable based on a specified type.
Definition: Enumerable.cs:2501
static double Average< TSource >(this IEnumerable< TSource > source, Func< TSource, int > selector)
Computes the average of a sequence of T:System.Int32 values that are obtained by invoking a transform...
Definition: Enumerable.cs:5163
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
static int Sum< TSource >(this IEnumerable< TSource > source, Func< TSource, int > selector)
Computes the sum of the sequence of T:System.Int32 values that are obtained by invoking a transform f...
Definition: Enumerable.cs:3709
static IEnumerable< int > Range(int start, int count)
Generates a sequence of integral numbers within a specified range.
Definition: Enumerable.cs:3084
static TSource SingleOrDefault< TSource >(this IEnumerable< TSource > source)
Returns the only element of a sequence, or a default value if the sequence is empty; this method thro...
Definition: Enumerable.cs:2920
void Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
static IEnumerable< IGrouping< TKey, TElement > > GroupBy< TSource, TKey, TElement >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Groups the elements of a sequence according to a specified key selector function and projects the ele...
Definition: Enumerable.cs:1786
bool MoveNext()
Advances the enumerator to the next element of the collection.
static TSource Last< TSource >(this IEnumerable< TSource > source)
Returns the last element of a sequence.
Definition: Enumerable.cs:2687
static int Sum(this IEnumerable< int > source)
Computes the sum of a sequence of T:System.Int32 values.
Definition: Enumerable.cs:3486
static bool All< TSource >(this IEnumerable< TSource > source, Func< TSource, bool > predicate)
Determines whether all elements of a sequence satisfy a condition.
Definition: Enumerable.cs:3198
static IEnumerable< TResult > Select< TSource, TResult >(this IEnumerable< TSource > source, Func< TSource, TResult > selector)
Projects each element of a sequence into a new form.
Definition: Enumerable.cs:996
static IOrderedEnumerable< TSource > ThenBy< TSource, TKey >(this IOrderedEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Performs a subsequent ordering of the elements in a sequence in ascending order according to a key.
Definition: Enumerable.cs:1681
static TResult Max< TSource, TResult >(this IEnumerable< TSource > source, Func< TSource, TResult > selector)
Invokes a transform function on each element of a generic sequence and returns the maximum resulting ...
Definition: Enumerable.cs:4847
static float Min(this IEnumerable< float > source)
Returns the minimum value in a sequence of T:System.Single values.
Definition: Enumerable.cs:3966
static float Sum(this IEnumerable< float > source)
Computes the sum of a sequence of T:System.Single values.
Definition: Enumerable.cs:3575
static long Sum(this IEnumerable< long > source)
Computes the sum of a sequence of T:System.Int64 values.
Definition: Enumerable.cs:3531
static TSource ElementAtOrDefault< TSource >(this IEnumerable< TSource > source, int index)
Returns the element at a specified index in a sequence or a default value if the index is out of rang...
Definition: Enumerable.cs:3042
static ? long Min(this IEnumerable< long?> source)
Returns the minimum value in a sequence of nullable T:System.Int64 values.
Definition: Enumerable.cs:3941
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
static IEnumerable< TSource > Concat< TSource >(this IEnumerable< TSource > first, IEnumerable< TSource > second)
Concatenates two sequences.
Definition: Enumerable.cs:1878
static TSource ElementAt< TSource >(this IEnumerable< TSource > source, int index)
Returns the element at a specified index in a sequence.
Definition: Enumerable.cs:3004
Definition: __Canon.cs:3
static TAccumulate Aggregate< TSource, TAccumulate >(this IEnumerable< TSource > source, TAccumulate seed, Func< TAccumulate, TSource, TAccumulate > func)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition: Enumerable.cs:3427
static ? double Average(this IEnumerable< long?> source)
Computes the average of a sequence of nullable T:System.Int64 values.
Definition: Enumerable.cs:4954
static IEnumerable< TSource > TakeWhile< TSource >(this IEnumerable< TSource > source, Func< TSource, bool > predicate)
Returns elements from a sequence as long as a specified condition is true.
Definition: Enumerable.cs:1260
static double Sum(this IEnumerable< double > source)
Computes the sum of a sequence of T:System.Double values.
Definition: Enumerable.cs:3618
static TSource Single< TSource >(this IEnumerable< TSource > source)
Returns the only element of a sequence, and throws an exception if there is not exactly one element i...
Definition: Enumerable.cs:2837
static List< TSource > ToList< TSource >(this IEnumerable< TSource > source)
Creates a T:System.Collections.Generic.List`1 from an T:System.Collections.Generic....
Definition: Enumerable.cs:2286
static IOrderedEnumerable< TSource > OrderBy< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Sorts the elements of a sequence in ascending order according to a key.
Definition: Enumerable.cs:1623
static ? float Max(this IEnumerable< float?> source)
Returns the maximum value in a sequence of nullable T:System.Single values.
Definition: Enumerable.cs:4571
static ? float Sum(this IEnumerable< float?> source)
Computes the sum of a sequence of nullable T:System.Single values.
Definition: Enumerable.cs:3595
static IOrderedEnumerable< TSource > OrderByDescending< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Sorts the elements of a sequence in descending order according to a key.
Definition: Enumerable.cs:1652
static ? long Sum(this IEnumerable< long?> source)
Computes the sum of a sequence of nullable T:System.Int64 values.
Definition: Enumerable.cs:3552
static IEnumerable< TResult > GroupJoin< TOuter, TInner, TKey, TResult >(this IEnumerable< TOuter > outer, IEnumerable< TInner > inner, Func< TOuter, TKey > outerKeySelector, Func< TInner, TKey > innerKeySelector, Func< TOuter, IEnumerable< TInner >, TResult > resultSelector)
Correlates the elements of two sequences based on equality of keys and groups the results....
Definition: Enumerable.cs:1540
static IEnumerable< TResult > GroupBy< TSource, TKey, TResult >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TKey, IEnumerable< TSource >, TResult > resultSelector)
Groups the elements of a sequence according to a specified key selector function and creates a result...
Definition: Enumerable.cs:1817
static TSource Max< TSource >(this IEnumerable< TSource > source)
Returns the maximum value in a generic sequence.
Definition: Enumerable.cs:4656
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
static IEnumerable< TSource > Intersect< TSource >(this IEnumerable< TSource > first, IEnumerable< TSource > second)
Produces the set intersection of two sequences by using the default equality comparer to compare valu...
Definition: Enumerable.cs:2060
static IOrderedEnumerable< TSource > ThenByDescending< TSource, TKey >(this IOrderedEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Performs a subsequent ordering of the elements in a sequence in descending order, according to a key.
Definition: Enumerable.cs:1718
static long LongCount< TSource >(this IEnumerable< TSource > source)
Returns an T:System.Int64 that represents the total number of elements in a sequence.
Definition: Enumerable.cs:3291
static float Average(this IEnumerable< float > source)
Computes the average of a sequence of T:System.Single values.
Definition: Enumerable.cs:4988
static ILookup< TKey, TSource > ToLookup< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Creates a T:System.Linq.Lookup`2 from an T:System.Collections.Generic.IEnumerable`1 according to a sp...
Definition: Enumerable.cs:2395
static IEnumerable< TSource > Except< TSource >(this IEnumerable< TSource > first, IEnumerable< TSource > second)
Produces the set difference of two sequences by using the default equality comparer to compare values...
Definition: Enumerable.cs:2119
static IEnumerable< TSource > Union< TSource >(this IEnumerable< TSource > first, IEnumerable< TSource > second)
Produces the set union of two sequences by using the default equality comparer.
Definition: Enumerable.cs:1998
static ? double Min(this IEnumerable< double?> source)
Returns the minimum value in a sequence of nullable T:System.Double values.
Definition: Enumerable.cs:4063
static IEnumerable< TSource > Distinct< TSource >(this IEnumerable< TSource > source)
Returns distinct elements from a sequence by using the default equality comparer to compare values.
Definition: Enumerable.cs:1952
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
static decimal Min(this IEnumerable< decimal > source)
Returns the minimum value in a sequence of T:System.Decimal values.
Definition: Enumerable.cs:4088
new bool Equals(object x, object y)
Determines whether the specified objects are equal.
static ? double Average(this IEnumerable< int?> source)
Computes the average of a sequence of nullable T:System.Int32 values.
Definition: Enumerable.cs:4890
static IEnumerable< TResult > Empty< TResult >()
Returns an empty T:System.Collections.Generic.IEnumerable`1 that has the specified type argument.
Definition: Enumerable.cs:3131
static Dictionary< TKey, TSource > ToDictionary< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Creates a T:System.Collections.Generic.Dictionary`2 from an T:System.Collections.Generic....
Definition: Enumerable.cs:2307
static ? decimal Min(this IEnumerable< decimal?> source)
Returns the minimum value in a sequence of nullable T:System.Decimal values.
Definition: Enumerable.cs:4124
Enumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.Generic.List`1.
Definition: List.cs:1020
static long Min(this IEnumerable< long > source)
Returns the minimum value in a sequence of T:System.Int64 values.
Definition: Enumerable.cs:3905
static TSource Aggregate< TSource >(this IEnumerable< TSource > source, Func< TSource, TSource, TSource > func)
Applies an accumulator function over a sequence.
Definition: Enumerable.cs:3392
static double Max(this IEnumerable< double > source)
Returns the maximum value in a sequence of T:System.Double values.
Definition: Enumerable.cs:4474
static int Max(this IEnumerable< int > source)
Returns the maximum value in a sequence of T:System.Int32 values.
Definition: Enumerable.cs:4352
static IEnumerable< TResult > SelectMany< TSource, TResult >(this IEnumerable< TSource > source, Func< TSource, IEnumerable< TResult >> selector)
Projects each element of a sequence to an T:System.Collections.Generic.IEnumerable`1 and flattens the...
Definition: Enumerable.cs:1079
static IEnumerable< TResult > Cast< TResult >(this IEnumerable source)
Casts the elements of an T:System.Collections.IEnumerable to the specified type.
Definition: Enumerable.cs:2529
static ? float Average(this IEnumerable< float?> source)
Computes the average of a sequence of nullable T:System.Single values.
Definition: Enumerable.cs:5014
static readonly Comparer Default
Represents an instance of T:System.Collections.Comparer that is associated with the P:System....
Definition: Comparer.cs:16
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
The Add key (the addition key on the numeric keypad).
static long Max(this IEnumerable< long > source)
Returns the maximum value in a sequence of T:System.Int64 values.
Definition: Enumerable.cs:4413
Defines an indexer, size property, and Boolean search method for data structures that map keys to T:S...
Definition: ILookup.cs:10
Represents a collection of keys each mapped to one or more values.
Definition: Lookup.cs:10
static TResult Aggregate< TSource, TAccumulate, TResult >(this IEnumerable< TSource > source, TAccumulate seed, Func< TAccumulate, TSource, TAccumulate > func, Func< TAccumulate, TResult > resultSelector)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accu...
Definition: Enumerable.cs:3457
Provides a set of static (Shared in Visual Basic) methods for querying objects that implement T:Syste...
Definition: Enumerable.cs:9
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
static IEnumerable< TResult > SelectMany< TSource, TCollection, TResult >(this IEnumerable< TSource > source, Func< TSource, int, IEnumerable< TCollection >> collectionSelector, Func< TSource, TCollection, TResult > resultSelector)
Projects each element of a sequence to an T:System.Collections.Generic.IEnumerable`1,...
Definition: Enumerable.cs:1149
static ? decimal Sum(this IEnumerable< decimal?> source)
Computes the sum of a sequence of nullable T:System.Decimal values.
Definition: Enumerable.cs:3683
Represents a collection of keys and values.To browse the .NET Framework source code for this type,...
Definition: Dictionary.cs:17
static ? int Max(this IEnumerable< int?> source)
Returns the maximum value in a sequence of nullable T:System.Int32 values.
Definition: Enumerable.cs:4388
static ILookup< TKey, TElement > ToLookup< TSource, TKey, TElement >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Creates a T:System.Linq.Lookup`2 from an T:System.Collections.Generic.IEnumerable`1 according to spec...
Definition: Enumerable.cs:2426
static double Average(this IEnumerable< int > source)
Computes the average of a sequence of T:System.Int32 values.
Definition: Enumerable.cs:4860
static int Min(this IEnumerable< int > source)
Returns the minimum value in a sequence of T:System.Int32 values.
Definition: Enumerable.cs:3844
static double Min(this IEnumerable< double > source)
Returns the minimum value in a sequence of T:System.Double values.
Definition: Enumerable.cs:4027
static IEnumerable< TSource > SkipWhile< TSource >(this IEnumerable< TSource > source, Func< TSource, bool > predicate)
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaini...
Definition: Enumerable.cs:1363
static TSource LastOrDefault< TSource >(this IEnumerable< TSource > source)
Returns the last element of a sequence, or a default value if the sequence contains no elements.
Definition: Enumerable.cs:2765
int ManagedThreadId
Gets a unique identifier for the current managed thread.
Definition: Thread.cs:55
static ? decimal Average(this IEnumerable< decimal?> source)
Computes the average of a sequence of nullable T:System.Decimal values.
Definition: Enumerable.cs:5129
static IEnumerable< IGrouping< TKey, TSource > > GroupBy< TSource, TKey >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector)
Groups the elements of a sequence according to a specified key selector function.
Definition: Enumerable.cs:1755
static IEnumerable< TSource > Where< TSource >(this IEnumerable< TSource > source, Func< TSource, bool > predicate)
Filters a sequence of values based on a predicate.
Definition: Enumerable.cs:928
static IEnumerable< TSource > Prepend< TSource >(this IEnumerable< TSource > source, TSource element)
Adds a value to the beginning of the sequence.
Definition: Enumerable.cs:5323
static IEnumerable< TSource > Reverse< TSource >(this IEnumerable< TSource > source)
Inverts the order of the elements in a sequence.
Definition: Enumerable.cs:2177
static Dictionary< TKey, TElement > ToDictionary< TSource, TKey, TElement >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector)
Creates a T:System.Collections.Generic.Dictionary`2 from an T:System.Collections.Generic....
Definition: Enumerable.cs:2344
static TResult Min< TSource, TResult >(this IEnumerable< TSource > source, Func< TSource, TResult > selector)
Invokes a transform function on each element of a generic sequence and returns the minimum resulting ...
Definition: Enumerable.cs:4339
static ? float Min(this IEnumerable< float?> source)
Returns the minimum value in a sequence of nullable T:System.Single values.
Definition: Enumerable.cs:4002
static ? int Min(this IEnumerable< int?> source)
Returns the minimum value in a sequence of nullable T:System.Int32 values.
Definition: Enumerable.cs:3880
static ? double Max(this IEnumerable< double?> source)
Returns the maximum value in a sequence of nullable T:System.Double values.
Definition: Enumerable.cs:4510
static TSource First< TSource >(this IEnumerable< TSource > source)
Returns the first element of a sequence.
Definition: Enumerable.cs:2559
static ? double Sum(this IEnumerable< double?> source)
Computes the sum of a sequence of nullable T:System.Double values.
Definition: Enumerable.cs:3638
static IEnumerable< TSource > Take< TSource >(this IEnumerable< TSource > source, int count)
Returns a specified number of contiguous elements from the start of a sequence.
Definition: Enumerable.cs:1226
static float Max(this IEnumerable< float > source)
Returns the maximum value in a sequence of T:System.Single values.
Definition: Enumerable.cs:4535
static IEnumerable< TResult > Join< TOuter, TInner, TKey, TResult >(this IEnumerable< TOuter > outer, IEnumerable< TInner > inner, Func< TOuter, TKey > outerKeySelector, Func< TInner, TKey > innerKeySelector, Func< TOuter, TInner, TResult > resultSelector)
Correlates the elements of two sequences based on matching keys. The default equality comparer is use...
Definition: Enumerable.cs:1445
static IEnumerable< TResult > GroupBy< TSource, TKey, TElement, TResult >(this IEnumerable< TSource > source, Func< TSource, TKey > keySelector, Func< TSource, TElement > elementSelector, Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Groups the elements of a sequence according to a specified key selector function and creates a result...
Definition: Enumerable.cs:1833
static ? decimal Max(this IEnumerable< decimal?> source)
Returns the maximum value in a sequence of nullable T:System.Decimal values.
Definition: Enumerable.cs:4632
static IEnumerable< TSource > Skip< TSource >(this IEnumerable< TSource > source, int count)
Bypasses a specified number of elements in a sequence and then returns the remaining elements.
Definition: Enumerable.cs:1328
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
Definition: ICollection.cs:14
static decimal Max(this IEnumerable< decimal > source)
Returns the maximum value in a sequence of T:System.Decimal values.
Definition: Enumerable.cs:4596
static TSource Min< TSource >(this IEnumerable< TSource > source)
Returns the minimum value in a generic sequence.
Definition: Enumerable.cs:4148
static decimal Sum(this IEnumerable< decimal > source)
Computes the sum of a sequence of T:System.Decimal values.
Definition: Enumerable.cs:3662
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
static ? double Average(this IEnumerable< double?> source)
Computes the average of a sequence of nullable T:System.Double values.
Definition: Enumerable.cs:5071
static int Count< TSource >(this IEnumerable< TSource > source)
Returns the number of elements in a sequence.
Definition: Enumerable.cs:3226
static bool SequenceEqual< TSource >(this IEnumerable< TSource > first, IEnumerable< TSource > second)
Determines whether two sequences are equal by comparing the elements by using the default equality co...
Definition: Enumerable.cs:2204
static IEnumerable< TResult > Repeat< TResult >(TResult element, int count)
Generates a sequence that contains one repeated value.
Definition: Enumerable.cs:3110
static IEnumerable< TSource > AsEnumerable< TSource >(this IEnumerable< TSource > source)
Returns the input typed as T:System.Collections.Generic.IEnumerable`1.
Definition: Enumerable.cs:2258
static double Average(this IEnumerable< long > source)
Computes the average of a sequence of T:System.Int64 values.
Definition: Enumerable.cs:4924
The exception that is thrown when a requested method or operation is not implemented.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
static double Average(this IEnumerable< double > source)
Computes the average of a sequence of T:System.Double values.
Definition: Enumerable.cs:5045
static TSource FirstOrDefault< TSource >(this IEnumerable< TSource > source)
Returns the first element of a sequence, or a default value if the sequence contains no elements.
Definition: Enumerable.cs:2623
static bool Any< TSource >(this IEnumerable< TSource > source)
Determines whether a sequence contains any elements.
Definition: Enumerable.cs:3144
static IEnumerable< TResult > Zip< TFirst, TSecond, TResult >(this IEnumerable< TFirst > first, IEnumerable< TSecond > second, Func< TFirst, TSecond, TResult > resultSelector)
Applies a specified function to the corresponding elements of two sequences, producing a sequence of ...
Definition: Enumerable.cs:1914
static bool Contains< TSource >(this IEnumerable< TSource > source, TSource value)
Determines whether a sequence contains a specified element by using the default equality comparer.
Definition: Enumerable.cs:3347
static IEnumerable< TSource > DefaultIfEmpty< TSource >(this IEnumerable< TSource > source)
Returns the elements of the specified sequence or the type parameter's default value in a singleton c...
Definition: Enumerable.cs:2455
static ? int Sum(this IEnumerable< int?> source)
Computes the sum of a sequence of nullable T:System.Int32 values.
Definition: Enumerable.cs:3507
static decimal Average(this IEnumerable< decimal > source)
Computes the average of a sequence of T:System.Decimal values.
Definition: Enumerable.cs:5102
Creates and controls a thread, sets its priority, and gets its status.
Definition: Thread.cs:18