標準入力から入力を読み込んで、作成したListに一文字ずつ代入したいです。
解決方法、他の方法が分かる方がおりましたら教えていただきたいです。
using System;
using System.Collections.Generic;
public class Hello{
public static void Main(){
string word = Console.ReadLine(); var list = new List<string>(); var a = word[0]; var b = word[1]; var c = word[2]; list.Add(a); list.Add(b); list.Add(c); foreach(var moji in list){ Console.Write(moji); } }
}
入力
abc
コンパイルエラー
Main.cs(13,18): error CS1502: The best overloaded method match for System.Collections.Generic.List<string>.Add(string)' has some invalid arguments /usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error) Main.cs(13,22): error CS1503: Argument
#1' cannot convert char' expression to type
string'
Main.cs(14,18): error CS1502: The best overloaded method match for System.Collections.Generic.List<string>.Add(string)' has some invalid arguments /usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error) Main.cs(14,22): error CS1503: Argument
#1' cannot convert char' expression to type
string'
Main.cs(15,18): error CS1502: The best overloaded method match for System.Collections.Generic.List<string>.Add(string)' has some invalid arguments /usr/lib/mono/4.5/mscorlib.dll (Location of the symbol related to previous error) Main.cs(15,22): error CS1503: Argument
#1' cannot convert char' expression to type
string'
回答1件
あなたの回答
tips
プレビュー