Iterating over a collection

You are iterating over a collection when working with C# in .Net.

In the given context, which of these is a valid syntax for the finally clause when there is no implicit conversion from the type of enumerator to IDisposable?

Options
1.finally 
{ 
 (enumerator as IDisposable)?.Dispose(); 
}
2.finally 
{ 
}
3.finally
{
 ((IDisposable)enumerator).Dispose();
}

4.None of these

Related Posts

Close Bitnami banner
Bitnami