首页 新闻 会员 周边

c# 的一个方法的bug

0
[已解决问题] 解决于 2019-04-13 18:38

using System;
namespace ns{
class aa{

static void Main(string[] args){

string[] starray = new string[]{"Down the way nights are dark",
     "And the sun shines daily on the mountain top",
     "I took a trip on a sailing ship",
     "And when I reached Jamaica",
     "I made a stop"};

string aa= String.Join(".",starray);
Console.WriteLine(aa);
     Console.ReadKey() ;

}
}
}

错误:

Down the way nights are dark.And the sun shines daily on the mountain top.I took a trip on a sailing ship.And when I reached Jamaica.I made a stop

Unhandled Exception: System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
at System.Console.ReadKey(Boolean intercept)
at ns.aa.Main(String[] args)

fangpengcheng_方鹏程的主页 fangpengcheng_方鹏程 | 初学一级 | 园豆:4
提问于:2019-04-03 13:58
< >
分享
最佳答案
1

这是因为你在 winform 程序里调用ReadKey,他无法读取键,你换成 Read() 或 ReadLine() 就行了;或者写到 控制台输出程序里

奖励园豆:5
三人乐乐 | 老鸟四级 |园豆:4819 | 2019-04-03 14:37

无法读取键什么意思,大佬请教,俺是小菜鸟

fangpengcheng_方鹏程 | 园豆:4 (初学一级) | 2019-04-04 08:51

@xiaofang.bk:
ReadKey()函数作用:获取用户按下的下一个字符或功能键。 按下的键显示在控制台窗口中。
因为你是 winform 程序,没有一个这个窗口,所以不能输入,这就是无法读取按键的意思。

三人乐乐 | 园豆:4819 (老鸟四级) | 2019-04-04 10:04
其他回答(1)
0

我没遇到这个bug

刘下来 | 园豆:919 (小虾三级) | 2019-04-04 09:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册