【发布时间】:2020-03-19 23:14:29
【问题描述】:
我写了一个简单的代码,我的程序需要两个输入,一个是姓名,第二个是号码(电话号码)。 我写了一节来查找联系人。 当用户输入 1 时,他应该添加姓名和电话号码,然后用户可以输入 1 或 2(1 用于添加联系人,2 用于搜索)当用户再次输入 1 时,所有旧日期以及删除,我不想要这个请帮忙。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace project_01
{
class Program
{
static void Main(string[] args)
{
string[] names = new string[5];
string[] phonenumb = new string[5];
bool itsTrue;
//int counter;
string help = @"enter 1 for add contact.
enter 2 for exit.0
enter 3 for search";
Console.WriteLine(help);
while (true)
{
Console.Write("=>");
int input = Convert.ToInt32(Console.ReadLine());
if (input == 1)
{
for (int i = 0; i < names.Length;)
{
Console.Write("name : ");
names[i] = Console.ReadLine();
Console.Write("number : ");
phonenumb[i] = Console.ReadLine();
i++;
break;
}
}
else if (input == 2)
{
Console.Write("enter y for exir and n to stay: ");
string exit = Console.ReadLine().ToUpper();
if (exit == "Y")
{
break;
}
else if (exit == "N")
{
continue;
}
}
else if (input == 3)
{
Console.Write("enter the name: ");
string search = Console.ReadLine();
itsTrue = false;
for (int j = 0; j < names.Length; j++)
{
if (search == names[j])
{
Console.WriteLine("name: {0}", names[j]);
Console.WriteLine("number:{0}", phonenumb[j]);
itsTrue = true;
break;
}
}
if (!itsTrue)
{
Console.WriteLine("content not found.");
}
}
}
}
}
}
【问题讨论】: