Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Major difference between Foreach and Using

Tags:

c#

foreach

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.

like image 867
Kalai Avatar asked Dec 19 '25 02:12

Kalai


1 Answers

  1. Nope
  2. Nope, foreach will dispose of your IEnumerable if it implements IDisposable.
like image 119
leppie Avatar answered Dec 20 '25 16:12

leppie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!