我正在尝试在 Windows 控制台应用程序中制作一个简单的电话目录程序。我使用了 SortedDictionary,其中 Key 是名称,Value 是数字,List 是地址,StringDictionary 是电子邮件 ID。我将所有这些都放在一个名为 Directory 的类中,然后通过 Main 中的一个实例调用它。我在枚举目录时遇到问题。我想在同一行打印一个人的所有四个条目。谁能告诉我应该如何进行。这就是我尝试的方式。我很确定我的逻辑中有很多错误..抱歉给您带来不便:-
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();
}
}
谢谢。