简体   繁体   English

占位符中 -5 的目的是什么? c#

[英]What is the purpose of -5 in placeholder? c#

We've been creating a program where it has to show the table or array.我们一直在创建一个程序,它必须显示表格或数组。 I just want to know the purpose of -5 in the placeholder Console.Write("{0, -5}", Greater[row, col]);我只想知道占位符Console.Write("{0, -5}", Greater[row, col]);中 -5 的用途

-5 is a formatting specifier to determine the width of the output string for this placeholder -5 是一个格式说明符,用于确定此占位符的 output 字符串的宽度

5 means the string will be at least 5 chars wide (padded with spaces) and the - means the value produced by accessing the Greater array will be aligned to the left 5表示字符串至少有 5 个字符宽(用空格填充), -表示访问更大数组产生的值将左对齐

If the value in Greater at that row,col is 1.2 the output will be "1.2 "如果该行的 Greater 中的值,col 为 1.2,则 output 将为"1.2 "

If the value were 1.23456789 the output would not be cut off at 5 wide.如果值为 1.23456789,则 output不会在 5 宽处被切断。 To ensure the data is formatted to a certain presentation you can add another formatting specifier after a colon, to dictate how the number will be formatted.为确保将数据格式化为特定的演示文稿,您可以在冒号后添加另一个格式化说明符,以指示数字的格式化方式。 For more info see "Control Spacing" onwards in https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0有关详细信息,请参阅https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=net-5.0中的“控制间距”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM