If I have a method with a using block like this…
public IEnumerable<Person> GetPersons()
{
using (var context = new linqAssignmentsDataContext())
{
return context.Persons.Where(p => p.LastName.Contans("dahl"));
}
}
…that returns the value from within the using block, does the IDisposable object still get disposed?
Yes it does. The disposing of the object occurs in a finally block which executes even in the face of a return call. It essentially expands out to the following code