Yes, foreach will call Dispose() on the enumerator if it implements IDisposable.
More Related Contents:
- Performance loss caused by Linq [duplicate]
- Do HttpClient and HttpClientHandler have to be disposed between requests?
- How do you get the index of the current iteration of a foreach loop?
- Is a LINQ statement faster than a ‘foreach’ loop?
- Update all objects in a collection using LINQ
- How to get values of selected items in CheckBoxList with foreach in ASP.NET C#?
- Has foreach’s use of variables been changed in C# 5?
- Performance difference for control structures ‘for’ and ‘foreach’ in C#
- How do you reconcile IDisposable and IoC?
- Modify Struct variable in a Dictionary
- returning in the middle of a using block
- Foreach loop, determine which is the last iteration of the loop
- Does foreach evaluate the array at every iteration?
- c# foreach (property in object)… Is there a simple way of doing this?
- “Nested foreach” vs “lambda/linq query” performance(LINQ-to-Objects) [closed]
- foreach with index [duplicate]
- Intelligent way of removing items from a List while enumerating in C#
- What does Process.Dispose() actually do?
- Why can’t we assign a foreach iteration variable, whereas we can completely modify it with an accessor?
- When should I use GC.SuppressFinalize()?
- Who should call Dispose on IDisposable objects when passed into another object?
- What is the difference between using and await using? And how can I decide which one to use?
- Check for null in foreach loop
- Guidelines For Dispose() and Ninject
- Why would a class implement IDisposable explicitly instead of implicitly?
- Do I need to Dispose a SemaphoreSlim?
- Who Disposes of an IDisposable public property?
- Determining if IDisposable should extend an interface or be implemented on a class implementing said interface
- Starting a new thread in a foreach loop
- How do I copy items from list to list without foreach?