using System;
using System.Collections.Generic;
using System.Text;namespace test
{
class Program
{
static void Main(string[] args)
{
string str = "a";
string str2 = "b";
Console.WriteLine(str,str2);
}
}
}
为什么只输出了str?谢谢
using System.Collections.Generic;
using System.Text;namespace test
{
class Program
{
static void Main(string[] args)
{
string str = "a";
string str2 = "b";
Console.WriteLine(str,str2);
}
}
}
为什么只输出了str?谢谢
你应该调用的是Console.WriteLine(str);
Console.WriteLine(str2);
using System;
using System.Collections.Generic;
using System.Text; namespace test
{
class Program
{
static void Main(string[] args)
{
string str = "a:{0}";
string str2 = "b";
Console.WriteLine(str,str2);
//相当于下面的效果
Console.WriteLine("{0}:{1}",str,str2);
}
}
}
字符串用+来连接
这样写得话就可以输出了
Console.WriteLine(str+str2);
public static void WriteLine (
string format,
params Object[] arg
)
此方法使用 .NET Framework 的复合格式设置功能将对象的值转换为其文本表示形式,并将该表示形式嵌入字符串中。得到的字符串被写入输出流。 format 参数由零个或多个文本序列与零个或多个索引占位符混合组成,其中索引占位符称为格式项,它们与此方法的参数列表中的对象相对应。格式设置过程将每个格式项替换为对应对象的值的文本表示形式。 格式项的语法是 {index[,alignment][:formatString]},它指定了一个强制索引、格式化文本的可选长度和对齐方式,以及格式说明符字符的可选字符串,其中格式说明符字符用于控制如何设置相应对象的值的格式。
Console.WriteLine("{0}{1}",str,str2);