前提・実現したいこと
C#言語でstring型のListについての質問です。
コンソールから文字列を入力させ続け、何も入力せずEnterを押すと、それまで入力した文字列のが全て表示されるプログラムを作りなさい。このとき文字列は、Listで作った可変長配列に格納すること。
上記のような問題があるのですが、入力終了の判定がうまくいきません。
アドバイスお願いします。
発生している問題・エラーメッセージ
enterだけを押してもループを抜けません。
該当のソースコード
C#言語
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace probex6_4
{
class Program
{
static void Main(string[] args)
{
List<string> s = new List<string>();
int c = 0;
while (true)
{
Console.Write("文字列を入力:");
s.Add(Console.ReadLine());
if (s[c]=="")//ここがわかりません
{
break;
}
c++;
}
Console.WriteLine();
foreach(string i in s)
{
Console.Write(i + " ");
}
Console.WriteLine();
}
}
}
試したこと
if文での判定を"exit"などの文字列にしてみましたが、エラーが出てきます。
エラー内容
System.Collections.Generic.List1[System.String] System.Collections.Generic.List
1[System.String]
補足情報(FW/ツールのバージョンなど)
環境はvisualstadio2017です。
回答4件
あなたの回答
tips
プレビュー