“你能解释代码是如何工作的吗?”问题可以被关闭 [英] "Can you explain how the code works".. question can be closed

查看:58
本文介绍了“你能解释代码是如何工作的吗?”问题可以被关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Console.WriteLine("{0,2} + {1,2} = {2,2}\t{3,2} * {4,2} = {5,4}",
                             i, 100 - i, i + (100 - i),
                             i, 100 - i, i * (100 - i));

推荐答案

这是一个简单的输出到控制台指令。它以下列形式输出5个值:

It's a simple output-to-the-console instruction. It outputs 5 values in the form:
nn + nn = nn      nn * nn = nn



第一个参数(字符串)指定数据的呈现方式,其余参数提供要显示的值。

格式字符串中大括号中的每个项目处理一个值参数:所以 {0,2} 说插入第一个值参数, {1,2} 说插入第二个值参数等等。

在大括号内,第一个数字指的是值参数index:第一个为0,第二个为1,依此类推。

逗号和第二个数字是可选的,并指定值的格式化大小:在本例中为2,表示每个值在打印时至少为两个字符长,因此值为7将占用屏幕上的相同空间值为27.

\t 是一个特殊字符,它在两个标准之间提供一些空格输出的ts。


The first parameter (the string) specifies the way the data will be presented, the remaining ones provide the values to show.
Each item in curly brackets in the format string handles a single one of the value parameters: so {0,2} says "insert the first value parameter", {1,2} says "insert the second value parameter" and so forth.
Within the curly brackets, the first number refers to the value parameter index: 0 for the first, 1 for the second, and so forth.
The comma and the second number is optional, and specifies a formatted size for the value: in this case "2" which means that each value will be a minimum of two characters long when printed, so a value of 7 will occupy the same space on screen as a value of 27.
The \t is a "special character" which provides some space between the two parts of the output.


我想知道{0,2}是什么意思。现在我意识到包含'2'只是为了指定间距。



I was wondering what {0,2} meant. Now I realize that the '2' is included just to specify spacing.

Console.WriteLine("{0} + {1} = {2}\t{3} * {4} = {5}",
                             i, 100 - i, i + (100 - i),
                             i, 100 - i, i * (100 - i));









此代码会给出相同的结果....但是使用默认间距。





This code would give same results....but with the default spacing.


这篇关于“你能解释代码是如何工作的吗?”问题可以被关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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