I had started learning iterator methods and implementation of IEnumerators in c#. I got confused at a point regarding the yield return statement.
Suppose, I create an iterator method 'Iterator()' and I have a collection 'myCollection' containing items of type 'TCustom'. myCollection is a collection type that implements 'IEnumerable' but, type 'TCustom' does not implement it.
IEnumerable Iterator()
{
foreach(TCustom item in myCollection)
{
yield return item;
}
}
class RandomCollection : IEnumerable{....}
class TCustom {....}
RandomCollection myCollection = new RandomCollection();
so the yield statement is returning 'item' object of type 'TCustom' from 'myCollection'. If 'TCustom' is a custom type created from my source code, does it have to implement IEnumerable interface? And if type 'TCustom' does not implement 'IEnumerable' interface, can it be a return type of yield return statement? (yield return item;)