string.format vs + for string concatenatoin

Posted by AMissico on Stack Overflow See other posts from Stack Overflow or by AMissico
Published on 2012-03-20T23:18:00Z Indexed on 2012/03/20 23:29 UTC
Read the original article Hit count: 198

Filed under:
|

Which is better in respect to performance and memory utilization?

// + Operator
oMessage.Subject = "Agreement, # " + sNumber + ", Name: " + sName;

// String.Format
oMessage.Subject = string.Format("Agreement, # {0}, Name: {1}", sNumber, sName);

My preference is memory utilization. The + operator is used throughout the application. String.Format and StringBuilder is rarely use. I want to reduce the amount of memory fragmentation caused by excessive string allocations.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about string