Advertisement
Geralt1001

zad 6.6

Oct 23rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Mwzad66
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             IEnumerable<int> aa = new IEnumerable();
  15.         }
  16.  
  17.        
  18.     }
  19.  
  20.     public static class IenumerableExtend
  21.     {
  22.         public static bool IsEmpty<T>(this IEnumerable<T> input)
  23.         {
  24.             return input != null && input.Any();
  25.         }
  26.  
  27.         public static void Mean(this IEnumerable<int> input)
  28.         {
  29.             //
  30.         }
  31.         public static void MeanLength(this IEnumerable<string> input)
  32.         {
  33.             //
  34.         }
  35.     }
  36.  
  37.  
  38.  
  39.     class Example : IEnumerable<string>
  40.     {
  41.         List<string> _elements;
  42.  
  43.         public Example(string[] array)
  44.         {
  45.             this._elements = new List<string>(array);
  46.         }
  47.  
  48.         IEnumerator<string> IEnumerable<string>.GetEnumerator()
  49.         {
  50.             //Console.WriteLine("HERE");
  51.             return this._elements.GetEnumerator();
  52.         }
  53.  
  54.         IEnumerator IEnumerable.GetEnumerator()
  55.         {
  56.             return this._elements.GetEnumerator();
  57.         }
  58.     }
  59.  
  60.     class Program
  61.     {
  62.         static void Main()
  63.         {
  64.             Example example = new Example(
  65.                 new string[] { "cat", "dog", "bird" });
  66.             // The foreach-loop calls the generic GetEnumerator method.
  67.             // ... It then uses the List's Enumerator.
  68.             foreach (string element in example)
  69.             {
  70.                 Console.WriteLine(element);
  71.             }
  72.         }
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement