IEnumerable
Indexer
IEnumerable interface has only one method public IEnumerator GetEnumerator(), When you use a foreach loop to iterate over a collection that implements IEnumerable, the C# compiler automatically calls the GetEnumerator() method behind the scenes
IEnumerator
IEnumerator is a mechanism that allow to iterating over a collection in older code bases. After foreach loop introduced no developer uses IEnumerator in modern code
This interface has 3 properties 1) object Currect {get} 2) bool MoveNext() 3) void Reset
Its has two types generic type and non-generic type
Foreach loop is syntactic sugar. Uses GetEnumerator while loop and MoveNext() method
indexer which can give the index of a custom collection class
syntax could be : public T this[index] {get{ return TList[index] };set{TList[index]=value}}
ICollection
ICollection interface derives from IEnumerable
IList
IList interface derives from IEnumerable,ICollection
ReadOnlyCollection
Thread Safe, Prevents accidental modification, Small Implementation
yield
yield always work with an IEnumerable or Iterator
to break the loop we can use yield break within that IEnumerable loop
It has a generic interface IEnumerator<T> inherits IEnumerator
public T Current
object IEnumerator.Current => Current;
public bool MoveNext()
public void Reset()
public void Dispose()
yield is a powerful feature in C# for working with sequences, especially in scenarios where you want to avoid loading all data into memory at once.
int Count { get; }
bool IsReadOnly { get; }
void Add(T item);
void Clear();
bool Contains(T item);
void CopyTo(T[] array, int arrayIndex);
bool Remove(T item);
T this[int index]
IndexOf(T item)
Insert(int index, T item)
RemoveAt(int index)
this[int index] { get; set; }
private string[] TList= new string[10];