C # StringBuilder, String, Append

Source: Internet
Author: User

problem leads to:StringBuilder sqlquery = new StringBuilder ();
Sqlquery.append ("Select COUNT ([ProductID]) from ~~where [isdelete]= ' F ');

the difference between 1.StringBuilder and stringString aa= "123456";
aa+= "789";StringBuilder text=new StringBuilder ("123456", 12);
Text. Append ("789");If you output AA, and text you will find that their output content is the same. But the operation of AA is actually: first allocate an address space in memory, the space size is 6.
Then execute aa+= "789", the procedure is the connection string, "123456" and "789" and the address is reassigned in memory. Point the memory address of the AA to the memory address of "123456789".
That is, in memory is actually two space is allocated, the first memory space, in the later is the C # garbage processing mechanism to automatically dispose of,If we use 3 4 sentences to implement this process, then he does not allocate memory space again, he is in the text of the memory space in the operation. Here to illustrate that the next StringBuilder in the process of life variables can be our own to allocate his size, if the actual content beyond the memory space, he will automatically double. From The above example, we can know that the superiority of StringBuilder is in:
First: He doesn't need to allocate memory space every time. Therefore, the system does not need to deal with garbage;
Second: When we need to do multiple operations on a string multiple times, he is much more efficient than string 2.Append The Append method can be used to add a string representation of text or an object to the end of a string represented by the current StringBuilder object.
Stringbuilder.append appends the information to the end of the current StringBuilder. Stringbuilder.appendformat replaces the format specifier passed in the string with the formatted text.
Stringbuilder.insert Inserts a string or an object into the current StringBuilder object at the specified index.
Stringbuilder.remove removes the specified number of characters from the current StringBuilder object.

C # StringBuilder, String, Append

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: info-contact@alibabacloud.com 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.