I wish to make a small insurance application. The application asks your name and then checks if name already exists; if they exist then you get a message this name is already used.
if not then you will be asked what for insurance do you want and then on the screen you get a message the name is correctly signed up.
and i have a function that lists all my client's names and the kind of insurance as a generic list
I make a generic list and in my function i use foreach so i can print every item in the generic list everything works good but if i add a person to my list and i try back and write the same name i don't get error.
Question: Why I don't get a error? what is the problem actually?
Thank you in advance
my code is here under:
public static List<string> klantgegevens = new List<string>();
public static void Main(string[] args)
{
retry:
string naam;
int verzekeringkeuze;
string alleklantgegevens;
Console.WriteLine("wat is u naam");
naam = Console.ReadLine();
if (klantgegevens.Contains(naam))
{
Console.WriteLine("deze naam bestaat al");
}
else
{
Console.WriteLine("kies u soort verzekering: 1-auto,2-leven,3-woning");
verzekeringkeuze = int.Parse(Console.ReadLine());
switch (verzekeringkeuze)
{
case 1:
Console.WriteLine(alleklantgegevens = $"{naam}:auto");
break;
case 2:
Console.WriteLine(alleklantgegevens = $"{naam}:leven");
break;
case 3:
Console.WriteLine(alleklantgegevens = $"{naam}:woning");
break;
default:
break;
}
Console.WriteLine($"{naam} werd correct ingeschreven");
Console.ReadLine();
alleklantgegevens = $"{naam}:{verzekeringkeuze}";
klantgegevens.Add(alleklantgegevens);
}
Printall();
goto retry;
}
public static void Printall()
{
foreach (string gegevens in klantgegevens)
{
Console.WriteLine($"alle klantgegevens:{gegevens}");
}
Console.ReadLine();
}
没有错误,因为您检查 Contains(naam) 而不是 $"{naam}:{verzekeringkeuze}" 这是您放入列表中的内容。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.