Advertisement
bero_0401

Enumerable

Oct 4th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 KB | Source Code | 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 revision
  9. {
  10.     public class Employee : IEnumerable<PayItem>
  11.     {
  12.  
  13.         private readonly List<PayItem> _payItems = new();
  14.         public string Name { get; set; }
  15.        
  16.         public void AddPayItem(string name , int value)
  17.         {
  18.             if (string.IsNullOrEmpty(name))
  19.             {
  20.                 throw new ArgumentNullException("name");
  21.             }
  22.             PayItem payItem = new PayItem{ Name = name, Value = value};
  23.             _payItems.Add(payItem);
  24.      
  25.         }
  26.  
  27.  
  28.         // indexer properity
  29.         public PayItem this[int index]
  30.         {
  31.             get => _payItems[index];
  32.  
  33.         }
  34.  
  35.  
  36.  
  37.         public IEnumerator<PayItem> GetEnumerator()
  38.         {
  39.          //  return new PayItemsEnumerator(_payItems);
  40.          foreach (PayItem payItem in _payItems)
  41.             { yield return payItem; }
  42.         }
  43.  
  44.         IEnumerator IEnumerable.GetEnumerator()
  45.         {
  46.             throw new NotImplementedException();
  47.         }
  48.  
  49.  
  50.         //private class PayItemsEnumerator : IEnumerator<PayItem>
  51.         //{
  52.         //    private readonly List<PayItem> _payItems;
  53.         //    private int _currentIndex = -1;
  54.         //    public PayItemsEnumerator(List<PayItem> payItems)
  55.         //    {
  56.         //        _payItems = payItems;
  57.         //    }
  58.  
  59.         //    public PayItem Current => _payItems[_currentIndex];
  60.  
  61.         //    object IEnumerator.Current => Current;
  62.  
  63.         //    public void Dispose()
  64.         //    {
  65.         //        throw new NotImplementedException();
  66.         //    }
  67.  
  68.         //    public bool MoveNext()
  69.         //    {
  70.         //       return ++_currentIndex < _payItems.Count;
  71.         //    }
  72.  
  73.         //    public void Reset()
  74.         //    {
  75.         //        throw new NotImplementedException();
  76.         //    }
  77.         //}
  78.     }
  79.  
  80.  
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement