return statement inside a using

  • Thread starter Thread starter john_teague
  • Start date Start date
J

john_teague

I am using a statement similar to this:
using(SqlDataReader dr = ...){
dr.Read();
return Fill(dr);
}

will the using tag properly destroy the data reader after the return
statement?
 
john_teague said:
I am using a statement similar to this:
using(SqlDataReader dr = ...){
dr.Read();
return Fill(dr);
}

will the using tag properly destroy the data reader after the return
statement?

Yes, it will once it goes out of scope, ie after the return in your case.
 
Sure will.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
john_teague said:
I am using a statement similar to this:
using(SqlDataReader dr = ...){
dr.Read();
return Fill(dr);
}

will the using tag properly destroy the data reader after the return
statement?

Yes - it's exactly equivalent to using a try/finally.
 
Back
Top