c#中Console.Writeline()两种使用方式的不同?

dongge2010 2011-08-03 02:57:10
char[] trimChars = { ' ', 'e', 's' };
string userResponse = Console.ReadLine();
userResponse = userResponse.ToLower();
userResponse = userResponse.Trim(trimChars);
Console.WriteLine("The string is "+ userResponse);
if (userResponse == "y")
{
Console.WriteLine("It inlude the special char");
}
其中Console.WriteLine("The string is "+ userResponse);这句如果采用Console.WriteLine("The string is {0}", userResponse);就会出现异常这是什么原因?
...全文
237 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhujiazhi 2011-08-03
  • 打赏
  • 举报
回复
Console.WriteLine(string.Format("The string is {0}", userResponse))
蝶恋花雨 2011-08-03
  • 打赏
  • 举报
回复
最好加上format下然后再用{0},自己解决就好。结账吧。
dongge2010 2011-08-03
  • 打赏
  • 举报
回复
问题已找到,输入的问题,本身这两种输出的形式结果都是一样的
isjoe 2011-08-03
  • 打赏
  • 举报
回复
没看出什么问题,什么错误呢?是不是userResponse有问题
试试:
Console.WriteLine(string.format("The string is {0}",userResponse));

110,500

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧