Search code examples
c#stringcurly-braces

Curly braces in string {0}


I often see curly braces in a string usually containing a number, such as:

string something = "I have {0} cats";

Whilst I can work out what this means, I can say I've never read any documentation relating to its useage. The c# string documentation seems to be void of any information relating to these. Can anyone point me in the right direction?


Solution

  • Used in string.Format as a place holder for a value parameter. string.Format("I have {0} cats", 5); prints "I have 5 cats"

    So you could use string.Format(something, 5); and get the same result as above