Console.Write语法:格式字符串"{0,-25}"的含义是什么?吝啬的 [英] Console.Write syntax: what does the format string "{0, -25}" mean

查看:51
本文介绍了Console.Write语法:格式字符串"{0,-25}"的含义是什么?吝啬的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写C#代码

Console.Write("{0,-25}", company);

在上面的代码中,这"{0,-25}" 是什么意思?

In above code what does this "{0,-25}" thing mean?

推荐答案

您提到很难看到它的作用:那是因为它添加了空格,而这些空格很难在控制台中看到.尝试在输出之前和之后直接添加一个字符,这样您可以更清楚地看到空格,如以下示例所示:

You mention it's hard to see what it does: that's because it adds spaces and those are difficult to see in the console. Try adding a character directly before and after the output so you can more clearly see the space, like the examples below:

Console.WriteLine("[{0, -25}]", "Microsoft"); // Left aligned 
Console.WriteLine("[{0,  25}]", "Microsoft"); // Right aligned
Console.WriteLine("[{0,   5}]", "Microsoft"); // Ignored, Microsoft is longer than 5 chars

将导致此结果(带有空格)

Will result in this (with spaces)

[Microsoft                ]
[                Microsoft]
[Microsoft]

在控制台窗口中如下所示:

Which looks like this in the console window:

这篇关于Console.Write语法:格式字符串"{0,-25}"的含义是什么?吝啬的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆