前提
trackというアプリを使用して解いています。入力処理はGetStdin()です。
実現したいこと
- C#で設定された文字列内の数値で引き算をして一定以上ならgame set、それ以下ならcontinueと表示したい
発生している問題・エラーメッセージ
/root/src/src/MainApp.cs(23,24): error CS0117: 'Math' does not contain a definition for 'abs' [/root/src/MainApp.csproj] Math.Absの部分を修正した所 Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array. at MainApp.Main(String[] args) in /root/src/src/MainApp.cs:line 19(int.Parseの所) Command terminated by signal 6 上記のエラーコードが検出されました。
該当のソースコード
using System; using System.IO; using System.IO; using System.Collections.Generic; public class MainApp { static public void Main(string[] args) { string[] tbl = GetStdin(); int a = int.Parse(tbl[0]); int b = int.Parse(tbl[1]); int val = Math.Abs(a-b); if( val >= 10 ) { Console.WriteLine("game set"); } else { Console.WriteLine("continue"); } } static private string[] GetStdin() { var list = new List<string>(); string line; while ((line = Console.ReadLine()) != null) { list.Add(line); } return list.ToArray(); } } 言語名:C#
試したこと
文字列を数字に置き換えてfor文を使用しそのまま出力した→
for文の外に計算結果を排出できず
Math.Absの部分を修正した所
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
at MainApp.Main(String[] args) in /root/src/src/MainApp.cs:line 19(int.Parseの所)
Command terminated by signal 6
上記のエラーコードが検出されました。
回答2件
あなたの回答
tips
プレビュー