Using (xx = ...) Meaning

Source: Internet
Author: User
Subject: When is using used?
Author: Overmind (Overmind)
Level 1:
Reputation value: 96
Community: . NET technology. NET Framework
Problem points: 20
Replies: 3
Posting time: 2005-12-28 15:25:07
Public accountinfo signin (string userid, string password) {<br/> sqlparameter [] signonparms = getsignonparameters (); <br/> signonparms [0]. value = userid; <br/> signonparms [1]. value = password; <br/> using (sqldatareader RDR = sqlhelper. executereader (sqlhelper. conn_string_non_dtc, commandtype. text, SQL _select_account, signonparms) {<br/>... <br/>}</P> <p> Why is using used here? I have never understood the meaning of Using. Please tell me clearly. Me, thank you! <Br/>

Reply:Ben_na (stupid)() Credit: 100 2005-12-28 16:41:00 Score: 0
Some resources will be released after the application is used up. For example, after the file is opened, it must be closed. After the database is opened, it must be closed. <br/> This is generally the case </P> <p> xx = NULL; <br/> try {<br/> xx. open (); <br/>}finally {<br/> If (XX! = NULL) {<br/> xx. dispose (); <br/>}</P> <p> the dispose () method is the method used to interface idispose. </P> <p> you can think of writing <br/> using (xx = ...) {<br/> use it as needed! <Br/>}</P> <p> it is like try finally written above... <br/>
Reply:Imxh (elegant)() Credit: 100 2005-12-28 16:50:00 Score: 0

The variables declared in using () {}< br/> () are recycled after the {} statement body is executed to optimize memory resource management. <br/>

Using (sqldatareader RDR = sqlhelper. executereader (sqlhelper. conn_string_non_dtc, commandtype. Text, SQL _select_account, signonparms )){

Using (sqlconnection conn = new sqlconnection (sqlhelper. conn_string_non_dtc )){
Conn. open ();
Using (sqltransaction trans = conn. begintransaction ()){
Try {
Sqlhelper. executenonquery (trans, commandtype. Text, SQL _insert_signon, signonparms );
Sqlhelper. executenonquery (trans, commandtype. Text, SQL _insert_account, accountparms );
Sqlhelper. executenonquery (trans, commandtype. Text, SQL _insert_profile, profileparms );
Trans. Commit ();

} Catch {
Trans. rollback ();


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.