Click here to Skip to main content
15,922,696 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to know the fact that desktop in changed? Pin
Luc Pattyn22-Aug-07 13:10
sitebuilderLuc Pattyn22-Aug-07 13:10 
GeneralRe: How to know the fact that desktop in changed? Pin
dhami_naresh6-Sep-07 19:56
dhami_naresh6-Sep-07 19:56 
QuestionWindows service + COM STA Pin
SteveL1223422-Aug-07 7:29
SteveL1223422-Aug-07 7:29 
AnswerRe: Windows service + COM STA Pin
kubben22-Aug-07 8:29
kubben22-Aug-07 8:29 
AnswerRe: Windows service + COM STA Pin
SteveL1223423-Aug-07 5:01
SteveL1223423-Aug-07 5:01 
QuestionStringBuilder Pin
elwoofy22-Aug-07 6:47
elwoofy22-Aug-07 6:47 
AnswerRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 7:00
mentorGiorgi Dalakishvili22-Aug-07 7:00 
AnswerRe: StringBuilder Pin
Scott Dorman22-Aug-07 7:23
professionalScott Dorman22-Aug-07 7:23 
The StringBuilder is used when you have a lot of string manipulation, such as appending text inside of a loop. It's benefit comes from the fact that it doesn't need to create a new string instance each time it appends. Take the following loop:
C#
string result = String.Empty;
for (int i = 0; i <= 10000; i++)
{
   result += String.Format("i = {0}\n", i);
}
Each time through this loop, you are allocating a new instance of a string to hold the concatenated value. Changing this loop to:
C#
StringBuilder resultBuilder = new StringBuilder();
for (int i = 0; i <= 10000; i++)
{
   resultBuilder.AppendFormat("i = {0}\n", i);
}
string result = resultBuilder.ToString();
you don't have all of the string allocations.
You can't access the value of a StringBuilder in any meaningful way other than to call it's ToString() method, which retrieves the internal value as a string. However, once you have it as a string, you could access the string by individual character positions just like you would a char[].

Remember, string in .NET is not really equivalent to a char[] even though you can do a lot of the same operations; it is a first class data type.


Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 7:41
mentorGiorgi Dalakishvili22-Aug-07 7:41 
GeneralRe: StringBuilder Pin
Scott Dorman22-Aug-07 8:01
professionalScott Dorman22-Aug-07 8:01 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 8:05
mvePIEBALDconsult22-Aug-07 8:05 
GeneralRe: StringBuilder Pin
Scott Dorman22-Aug-07 8:13
professionalScott Dorman22-Aug-07 8:13 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 9:08
mvePIEBALDconsult22-Aug-07 9:08 
GeneralRe: StringBuilder Pin
Giorgi Dalakishvili22-Aug-07 9:23
mentorGiorgi Dalakishvili22-Aug-07 9:23 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 10:00
mvePIEBALDconsult22-Aug-07 10:00 
GeneralRe: StringBuilder Pin
Luc Pattyn22-Aug-07 13:21
sitebuilderLuc Pattyn22-Aug-07 13:21 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 14:43
mvePIEBALDconsult22-Aug-07 14:43 
GeneralRe: StringBuilder Pin
Luc Pattyn22-Aug-07 14:55
sitebuilderLuc Pattyn22-Aug-07 14:55 
GeneralRe: StringBuilder Pin
PIEBALDconsult22-Aug-07 17:57
mvePIEBALDconsult22-Aug-07 17:57 
QuestionRecording movement on a GUI of an application Pin
thedavejay22-Aug-07 6:27
thedavejay22-Aug-07 6:27 
AnswerRe: Recording movement on a GUI of an application Pin
Ravi Bhavnani22-Aug-07 10:46
professionalRavi Bhavnani22-Aug-07 10:46 
GeneralRe: Recording movement on a GUI of an application Pin
thedavejay23-Aug-07 6:32
thedavejay23-Aug-07 6:32 
QuestionDatagrid Pin
Brother Louis22-Aug-07 6:08
Brother Louis22-Aug-07 6:08 
Questionfrom CheckedListBox to DataGrid Pin
costavo22-Aug-07 4:55
costavo22-Aug-07 4:55 
AnswerRe: from CheckedListBox to DataGrid Pin
Vasudevan Deepak Kumar22-Aug-07 4:57
Vasudevan Deepak Kumar22-Aug-07 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.