Multiple choice technology databases

You are creating a method which returns a type that is compatible with the Foreach statement. Which criteria should the method meet?

  1. The method must return a type of either IEnumerator or Ienumerable

  2. The method must return a type of IComparable

  3. The method must explicitly contain a collection

  4. A and B

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In C#, the foreach statement can iterate over any type that implements IEnumerable or returns an IEnumerator. The method does not need to return IComparable, nor does it need to explicitly contain a collection internally, as long as the returned type supports the iteration pattern.