c#, can you think of anymore optimization in this code?
Posted
by Sha Le
on Stack Overflow
See other posts from Stack Overflow
or by Sha Le
Published on 2010-04-15T22:36:09Z
Indexed on
2010/04/15
22:43 UTC
Read the original article
Hit count: 243
c#
|optimization
Hi All: Look at the following code:
StringBuilder row = TemplateManager.GetRow("xyz"); // no control over this method
StringBuilder rows = new StringBuilder();
foreach(Record r in records)
{
StringBuilder thisRow = new StringBuilder(row.ToString());
thisRow.Replace("%firstName%", r.FirstName)
.Replace("%lastName%", r.LastName)
// all other replacement goes here
.Replace("%LastModifiedDate%", r.LastModifiedDate);
//finally append row to rows
rows.Append(thisRow);
}
Currently 3 StringBuilders and row.ToString() is inside a loop. Is there any room for further optimization here?
Thanks a bunch. :-)
© Stack Overflow or respective owner