Windows コンソール アプリケーションで簡単な電話帳プログラムを作成しようとしています。キーが名前で値が数値であるSortedDictionary、アドレスにリスト、電子メールIDにStringDictionaryを使用しました。これらすべてを Directory という名前のクラスに配置し、Main のインスタンスを介して呼び出しました。ディレクトリを列挙する際に問題に直面しています。ある人物の 4 つのエントリすべてを同じ行に印刷したいと考えています。誰がどうすればいいのか教えてもらえますか。これが私が試みていた方法です.私の論理には多くの間違いがあると確信しています..ご不便をおかけして申し訳ありません:-
public class Directry
{
List <string> Email_id= new List <string>();
SortedDictionary<string, int> Dict = new SortedDictionary<string, int>();
StringCollection Adress=new StringCollection();
public Directry(SortedDictionary<string, int> dict, StringCollection adress, List<string> email)
{
this.Dict = dict;
this.Email_id = email;
this.Adress = adress;
}
}
class Another
{
static void Main(string[] args)
{
SortedDictionary<string, int> dict = new SortedDictionary<string, int>();
List<string> email = new List<string>();
StringCollection adres = new StringCollection();
Directry dir = new Directry( dict, adres,email);
string key, adress, Email;
int numbr;
start_again:
for (int i = 0; i <2; i++)
{
Console.WriteLine("enter name to be added in the directory");
key = Console.ReadLine();
Console.WriteLine("enter number to be added in the directory");
numbr = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter address to be added in the directory");
adress = Console.ReadLine();
Console.WriteLine("enter your email-id to be added in the directory");
Email = Console.ReadLine();
dict.Add(key, numbr);
email.Add(Email);
adres.Add(adress);
}
Console.WriteLine("do you wish to continue-y/n?");
char c = Convert.ToChar(Console.ReadLine());
if (c == 'y')
{
Console.WriteLine("you said yes");
goto start_again;
}
else
{
Console.WriteLine("no more entries can be added");
Console.WriteLine("Name Number adress email");
foreach (object ot in dir)
{
Console.WriteLine(ot);
}
}
Console.ReadLine();
}
}
ありがとう。