What do the curly braces mean in C# strings?

后端 未结 5 1803
情书的邮戳
情书的邮戳 2021-02-14 22:40
while (rdr.Read())
{
    Console.WriteLine(\"Product: {0,-35} Total: {1,2}\", rdr[\"ProductName\"], rdr[\"Total\"]);
}

What does {0,-35} mean in this c

5条回答
  •  广开言路
    2021-02-14 23:13

    it's for Align String with Spaces

    To align string to the right or to the left use static method String.Format. To align string to the left (spaces on the right) use formatting patern with comma (,) followed by a negative number of characters: String.Format(„{0,–10}“, text). To right alignment use a positive number: {0,10}.

    have a look at

    http://www.csharp-examples.net/align-string-with-spaces/

提交回复
热议问题