0

Why shouldn't we simply use

 string s=product.Name+" has been saved";

instead of:

string s=string.Format("{0} has been saved", product.Name);
Aparan
  • 1,263
  • 3
  • 12
  • 17

3 Answers3

4

One naive reason would be that it helps to prevent exactly the string formatting issue that you've presented in your original (unedited) question i.e.

string s=product.Name+"has been saved";

requires an extra space. The format method aids readability.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
3

You could do that, no one say that you cannot. But mainly for readability, the second approach is prefered. It's even more obvious as soon as you concat more than 2 strings, it gets really messy, hard to read and mantain.

Claudio Redi
  • 67,454
  • 15
  • 130
  • 155
3

If you have many strings that you want to add, each + operation create new string.

For adding many strings you can use StringBuilder Class or String.Format

Mzf
  • 5,210
  • 2
  • 24
  • 37