0

So I'm currently learning C# and came across this example on the documentation:

DateTime date1 = new DateTime(2009, 7, 1);
TimeSpan hiTime = new TimeSpan(14, 17, 32);
decimal hiTemp = 62.1m; 
TimeSpan loTime = new TimeSpan(3, 16, 10);
decimal loTemp = 54.8m; 

string result1 = String.Format("Temperature on {0:d}:\n{1,11}: {2} degrees (hi)\n{3,11}: {4} degrees (lo)", 
                               date1, hiTime, hiTemp, loTime, loTemp);
Console.WriteLine(result1);
Console.WriteLine();

Console.WriteLine(result2);
// The example displays output like the following:
//       Temperature on 7/1/2009:
//          14:17:32: 62.1 degrees (hi)
//          03:16:10: 54.8 degrees (lo)

I understand that curly braces with just one number inside it mean to take that index of the argument and put it into the string, but what I don't understand is the second number behind the comma.

For example, what does 11 mean in {1,11} and {3,11}? What does adding a number behind a comma do when string formatting in C#?

Thanks in advance!

idude
  • 4,654
  • 8
  • 35
  • 49
  • Here's the documentation https://learn.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting?view=netframework-4.8 – juharr Dec 18 '19 at 22:20
  • 1
    I think the selected duplicate only works _if you already know the answer to the question_; this question is asking "What does _X_ do?" while that question is asking "How do I do _Y_?", to which the answer is "Use _X_." I think [What is String Format C# {0,12:N0} (colon and commas) means?](https://stackoverflow.com/q/34940355/150605) is a better duplicate since it asks the same question (and more). – Lance U. Matthews Dec 18 '19 at 22:24

0 Answers0