- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在帮助一位初学 c# 的 friend ,我们遇到了一个奇怪的问题。
第 31 行的 læn = Console.ReadLine()
被跳过。这会导致第 32 行的 .Parse
抛出错误。
如果我们在第一个之后添加一个额外的 læn = Console.ReadLine()
,它就会开始工作。
static void Main(string[] args)
{
double areal, læn1, høj1 = 0;
int figur;
string tekst, læn, høj;
tekst = ("Du skal nu vægle en figur.");
tekst += ("\nTryk 1 for rektangel");
tekst += ("\nTryk 2 for cirkel");
tekst += ("\nTryk 3 for en retvinklet trekant");
tekst += ("\nValg: ");
Console.Write("{0}", tekst);
figur = Console.Read();
switch (figur)
{
case '1':
{
Console.WriteLine("Du har valgt en rektangel. \nHvad er længden: ");
læn = Console.ReadLine(); //Line 31
læn1 = double.Parse(læn); //Line 32
Console.WriteLine("hvad er højden?");
høj = Console.ReadLine();
høj1 = double.Parse(høj);
areal = læn1 * høj1;
Console.WriteLine("\n{0} * {1} = {2}", læn, høj1, areal);
Console.ReadKey();
}
break;
default:
Console.WriteLine("Du har ikke valgt 1,2 eller 3");
Console.ReadKey();
break;
}
}
最佳答案
文档来自 Console.Read
状态:
The
Read
method blocks its return while you type input characters; it terminates when you press theEnter
key.
这意味着它只会在您按下 Enter
时返回一个值,无论您输入了多少内容。
由于您的下一条语句是 Console.ReadLine()
并且流中仍有一行结束等待读取(因为您按了 Enter
,但只处理了按下键),“吃掉”该语句。
考虑使用 Console.ReadKey()
相反。
关于c# - 开关盒忽略 Console.ReadLine(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26972653/
这个问题在这里已经有了答案: What could be the reason that `require` doesn't work in some places? (3 个回答) 6 个月前关闭。
我正在使用读取行从维基百科获取一些文本。但读取行仅返回列表,而不是我想要的文本。有什么方法可以使用替代方案或解决我的问题吗? public class mediawiki { public s
我正在编写一小段代码,其中涉及使用子进程运行一个脚本来监听一些实时数据 这是我的代码: def subscriber(): try: sub = subprocess.Pope
我已包括: #include "stdio.h" #include #include 我的编译器包含标志 -lreadline 但我仍然收到错误消息: fatal error: 'readl
使用 Term::Readline::readline 停止无限循环的正确方法是什么? ? 这样我一个都看不懂 0 #!/usr/bin/env perl use warnings; use stri
标题比我的实际目标更具体: 我有一个使用 GNU Readline 的命令行程序,主要用于命令历史记录(即使用向上箭头检索以前的命令)和其他一些细节。现在,程序的输出似乎散布在用户的输入中,有时是可以
在 ipython 中,如果我按“esc”,然后按“enter”(可能还有其他字符?),读行会中断。我无法再使用“向上”键搜索命令历史记录,并且某些命令(例如 control-K)失败。 有没有办法在
我在使用 readlines() 和 readline() 返回值时遇到问题,但在使用 read() 时却没有。任何人都知道这是怎么发生的?欣赏一下 with open('seatninger.txt
标题比我的实际目标更具体: 我有一个使用 GNU Readline 的命令行程序,主要用于命令历史记录(即使用向上箭头检索以前的命令)和其他一些细节。现在,程序的输出似乎散布在用户的输入中,有时是可以
我正在编写一个聊天客户端,它必须在接收用户输入的同时输出接收到的消息。 到目前为止,我已经 fork 成两个独立的进程,其中一个继续监听套接字连接并用 printf 写出接收到的字符串。另一个使用 r
我在 NetworkStream 上使用 StreamReader,我只想读取一行或多行,而另一个数据是 byte array(如文件数据)我不想在 StreamReader 中读取该文件数据,例如我
我遇到了这两个 API,用于在 C# 的简单控制台应用程序中读取用户的输入: System.Console.ReadLine() System.Console.In.ReadLine() 这是一个我试
yum 我的系统显示已安装 readline rlwrap-0.41]$ sudo yum install readline Loaded plugins: fastestmirror, presto
我尝试做 this tutorial在 Rust 中,到目前为止,我在将 C 库连接到 Rust 时遇到了很多问题。 C 等效代码: #include #include #include #in
我正在寻找 web Python的标题中提到的命令及其区别;但是,我并不满足于对这些命令有完整的基本理解。 假设我的文件只有以下内容。 This is the first time I am posi
你如何在 F# 中使用 Console.Readline?与 Console.Writeline 不同,当我调用它时,它并没有受到尊重。 最佳答案 如果你使用 let s = Console.Read
在一次面试中,面试官问我为什么 readline() 比 Python 中的 readlines() 慢很多? 我回答的是readlines()需要多次读取,需要更多的开销。 不知道我的回答对不对。
要在 OSX Lion 上完全运行 ipython 需要什么?我试图让 ipython 与 readline 一起工作,但没有成功。 我的做法: (在虚拟环境中) pip install ipytho
在 Nodejs 文档中,我看到: import EventEmitter from 'events'; import { readFile } from 'fs'; import fs, { rea
我写了一个简单的应用程序: #include #include #include #include int main() { char *user_input; while(u
我是一名优秀的程序员,十分优秀!