This could even be a simple question even a school boy can answer.
What is the similarities and differences between “ForEach” and “Using” (asked in an interview).
My assumption was
1)Both are enumerable
2) Using can handle memory resources,but foreach can’t.using supports IDisposable,foreach can’t.
I wish to know the answers.
Similarities:
But that is about where it ends…
usingdemandsIDisposable;foreachmight trigger fromIEnumerable[<T>], but is actually duck typed (you don’t needIEnumerableforforeach)usinghas a predictabletry/finallyconstruct;foreachmight involve aDispose()if the iterator isIEnumerable<T>If anything, I’d say
usingis closer tolockthan toforeach.