简体   繁体   English

不要在项目的通用列表中签入

[英]Do not check in the generic list of a item there is

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.我制作了一个通用列表,并在我的函数中使用 foreach 以便我可以打印通用列表中的每个项目,一切正常,但是如果我将一个人添加到我的列表中,然后我尝试回写相同的名称,我不会出错。

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}" 这是您放入列表中的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM