Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace revision
- {
- public class Employee : IEnumerable<PayItem>
- {
- private readonly List<PayItem> _payItems = new();
- public string Name { get; set; }
- public void AddPayItem(string name , int value)
- {
- if (string.IsNullOrEmpty(name))
- {
- throw new ArgumentNullException("name");
- }
- PayItem payItem = new PayItem{ Name = name, Value = value};
- _payItems.Add(payItem);
- }
- // indexer properity
- public PayItem this[int index]
- {
- get => _payItems[index];
- }
- public IEnumerator<PayItem> GetEnumerator()
- {
- // return new PayItemsEnumerator(_payItems);
- foreach (PayItem payItem in _payItems)
- { yield return payItem; }
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- throw new NotImplementedException();
- }
- //private class PayItemsEnumerator : IEnumerator<PayItem>
- //{
- // private readonly List<PayItem> _payItems;
- // private int _currentIndex = -1;
- // public PayItemsEnumerator(List<PayItem> payItems)
- // {
- // _payItems = payItems;
- // }
- // public PayItem Current => _payItems[_currentIndex];
- // object IEnumerator.Current => Current;
- // public void Dispose()
- // {
- // throw new NotImplementedException();
- // }
- // public bool MoveNext()
- // {
- // return ++_currentIndex < _payItems.Count;
- // }
- // public void Reset()
- // {
- // throw new NotImplementedException();
- // }
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement