Wednesday, 15 May 2013

C# using: constructor in a different method -



C# using: constructor in a different method -

all online examples can find c#'s using instantiate straight within using parentheses:

using (var cnx = new sqlconnection()) { }

i think next should deed identically, still seem have locked resources:

sqlconnection getconnection() { homecoming new sqlconnection(); } void foo() { using (var cnx = getconnection()) { } }

when step through programme , line next using's closing brace, i'd expect able alter db way want using sql server management studio, can't. when close app, errors go away.

this isn't segregated sql; i've experienced opening file steams in way. is: step past using block os won't allow external app alter file.

am violating part of using contract?

it's absolutely fine utilize method returns appropriate resource. in particular, pretty common:

using (var author = file.createtext(path)) { }

(and similar methods in file).

basically, isn't calling method or calling constructor - there must else wrong. if can create short complete programme demonstrating problem (ideally files instead of database) we're able help find out is problem, not isn't :)

c# using

No comments:

Post a Comment