C#-Console.WriteLine()不显示第二个参数 [英] C# - Console.WriteLine() does not showing the second Parameter

查看:37
本文介绍了C#-Console.WriteLine()不显示第二个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用不同的方法制作2个bool变量并尝试使用Console.WriteLine()方法显示它们时,在处理C#Basic数据类型时,显示了第一个变量,但没有显示第二个变量.我知道通过仅使用变量之间的+符号或在Console.WriteLine中使用占位符语法来获得所需输出的替代方法,但是我只想知道为什么第二个参数未显示的原因?如果有人知道原因,请回答.

While working on the C# Basic datatypes when I made 2 bool variables using different methods and as I tried to show them using Console.WriteLine() method, first variable was displayed but 2nd one did't display. I know the alternates to get the desired output by just using the + symbol between variables or using Placeholder syntax in Console.WriteLine,but I just want to know the reason, why the 2nd parameter is not showing ? If someone know the reason do answer.

这是我正在处理的代码.

this is the code that I'm working on.

        bool b1 = true;
        System.Boolean b2 = new System.Boolean();
        b2 = false;
        Console.WriteLine( b1.ToString() , b2.ToString() );

推荐答案

Console.WriteLine 用作 String.Format :

  • 第一个参数:格式化字符串.
  • 第2到第n:要用于的参数格式字符串.

这是您需要做的:

Console.WriteLine("{0} {1}", b1, b2);

这篇关于C#-Console.WriteLine()不显示第二个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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