Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は現在、ユーザーが行きたい方向を入力する迷路プログラムを作成していますが、Console.Read()メソッドのおかげで何でも入力できます。ユーザーが特定のスペースに入力できる文字数を制限する方法はありますか?
Console.Read()
リンク
StringBuilder sb = new StringBuilder(); int i, count = 0; while ((i = Console.Read()) != 13) // 13 = enter key (or other breaking condition) { if (++count > 200) break; sb.Append ((char)i); }
制限を必要な数に変更できます。
タイマーを設定することもでき、実行時間が 1 分を超えるとbreak.
break