如何将索引设置为布尔数据类型 [英] How to set index to bool datatype

查看:180
本文介绍了如何将索引设置为布尔数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
我是编程新手.我正在尝试在控制台应用程序中使用示例程序.
在定义具有bool数据类型的程序时,它们提供的示例代码为

Hi...
Im new to programming. Im trying sample programs in console application.
While defining a program with bool datatype ,they provide sample code as

public static void Main()
{
   bool content = true;
   bool noContent = false;

   Console.WriteLine("It is {0} that C# Station provides C# programming language content", content);
   Console.WriteLine("The statement above is not {0}", noContent);
}



但是我怀疑为什么不能给



But im having doubt why cant give as

console.writeline("The statement above is not {1}",nContent);



我尝试了此操作,并收到错误消息,因为索引(从零开始)必须大于或等于零且小于参数列表的大小."
但是不清楚错误...指导我



I tried this and got error as "Index (zero based) must be greater than or equal to zero and less than the size of the argument list."
But not clear in error...guide me

推荐答案

出现该错误的原因是因为您在Console.WriteLine中放置了{1}而没有{0}.您需要从零开始,因为它是从零开始的索引.

花括号内的数字表示您将在运行时传递给字符串的值.对于字符串内的每个唯一数字,您必须在字符串外具有一个变量以填充该空间.这些唯一的数字必须从零开始,并且必须是连续的.这并不意味着它们必须在字符串中按顺序排列,只是您不能跳过数字.这是一个示例:
The reason you are getting that error is because you put a {1} in the Console.WriteLine without having a {0}. You need to start from zero, since it is a zero-based index.

The numbers inside the curly braces represent the values you are going to pass into the string at runtime. For each unique number inside the string, you have to have a variable outside the string that will fill that space. These unique numbers have to start from zero and they have to be sequential. That does not mean that they have to be in order inside your string, just that you can''t skip numbers. Here is an example:
Console.WriteLine("This is the {1} variable and this is the {0}", "first", "second");


该行将输出这是第二个变量,这是第一个变量".我指定了两个变量,并混合了顺序,但这很好,因为我有一个零,而我有一个.零对应于在我的字符串之后传入的第一个变量,而一个对应于我在我的字符串之后传入的第二个变量.


This line will print out "This is the second variable and this is the first". I specified two variables and I mixed up the order, but it is perfectly fine because I have a zero and I have a one. The zero corresponds to the first variable passed in after my string and the one corresponds to the second variable I passed in after my string.


格式字符串中的0告诉格式化程序哪个构建结果字符串时要使用的参数.从字符串后面的第一个开始,从0向上索引参数.由于两个语句中都只有一个参数,因此它始终位于索引位置0,因此在位置1
没有一个参数
您可以这样写:
The 0 in your format string tells the formatter which parameter to use when building the resulting string. Parameters are indexed from 0 upwards starting with the first one after the string. Since you only have one parameter in both statements it is always at index position 0, you do not have one at position 1

You could write something like:
Console.WriteLine("The parameters are {1} and {0}", noContent, content);


演示如何选择它们.


to demonstrate how it selects them.


这篇关于如何将索引设置为布尔数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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