開発環境はVSの2019です。
教本のサンプルプログラムをビルドしたら、
エラー CS1061 'string' に 'Lenght' の定義が含まれておらず、型 'string' の最初の引数を受け付けるアクセス可能な拡張メソッド 'Lenght' が見つかりませんでした。using ディレクティブまたはアセンブリ参照が不足していないことを確認してください。
が出てしまい、ました。
↓書いたコードは
// array03.cs using System; class Array03 { public static void Main() { string[,] Name = new string[2, 5] { {"田中六郎","吉田一郎","太田太郎","鈴木四郎","岡田三郎"}, {"横田芳子","池田和子","目黒貴和子","武田信子","園田淳子"} }; int myClass, num; string strClass, strNum; while (true) { Console.Write("クラスは---"); strClass = Console.ReadLine(); if(strClass.Length >= 2) { Console.WriteLine("入力は1桁のみです"); continue; } if(Char.IsNumber(strClass, 0) != true) { Console.WriteLine("数字を入力してください"); continue; } myClass = Int32.Parse(strClass); if(myClass<=0 || myClass >= 3) { Console.WriteLine("クラスは1組か2組です"); continue; } break; } while (true) { Console.Write("出席番号は--"); strNum = Console.ReadLine(); if(strNum.Lenght >= 2) { Console.WriteLine("入力は1桁のみです"); continue; } if(Char.IsNumber(strNum, 0) != true) { Console.WriteLine("数字を入力してください"); continue; } num = Int32.Parse(strNum); if(num <=0 || num >= 6) { Console.WriteLine("出席番号は1番から5番までです"); continue; } break; } Console.WriteLine("{0}クラスの出席番号{1}番は{2}さんです", strClass, strNum, Name[myClass - 1, num - 1]); } }
調べたところ、「アセンブリ参照不足しているから、拡張メソッドを追加するのかな?」
というところまでしか理解ができませんでした…。
しかし、参照の追加→アセンブリを検索で Length で検索してもなにもヒットしません。
エラーの解釈が間違っているのでしょうか?何で検索すればよいか分かりません。
ご教授お願い致します。
回答3件
あなたの回答
tips
プレビュー