检查字符串输入是否等于字符串C#

检查字符串输入是否等于字符串C#,c#,C#,所以我有这个任务,我很难让这部分工作 我的想法是,我想列出所有动物的名字,然后让用户写下动物的名字,然后开始玩那个动物 我的观点是,我想检查这个名字是否与我所拥有的列表中的名字相等 // It's in my Animal class where I hold the information on every animal. List<Animal> animalList = new List<Animal>(); Console.WriteLine("Who do yo

所以我有这个任务,我很难让这部分工作

我的想法是,我想列出所有动物的名字,然后让用户写下动物的名字,然后开始玩那个动物

我的观点是,我想检查这个名字是否与我所拥有的列表中的名字相等

// It's in my Animal class where I hold the information on every animal.
List<Animal> animalList = new List<Animal>();
Console.WriteLine("Who do you want to play with?");
        List_Animal();

        string nameInput = Console.ReadLine();

        if (){

        } 

        else {
            Console.WriteLine("You wrote the wrong name. Try Again!");
        }

有什么帮助吗?

这里是它的主要部分

string nameInput = Console.ReadLine();

List<string> animals = new List<string>(){"Bird", "Duck"};
animals.Add("Dog");
animals.Add("Cat");

if (animals.Contains(nameInput))
    Console.WriteLine("Exists");
else
    Console.WriteLine("Not Exists");
string nameInput=Console.ReadLine();
列出动物=新列表(){“鸟”、“鸭”};
动物。加上(“狗”);
动物。加上(“猫”);
if(动物。包含(名称输入))
Console.WriteLine(“存在”);
其他的
Console.WriteLine(“不存在”);

您需要先获取动物列表,然后检查该列表,查看是否有任何元素与
nameInput
匹配

List<Animal> animalList = new List<Animal>(); //Get the animal list here.
        if(animalList.Any(x=>x.name == nameInput))
        {

        }
        else {
         Console.WriteLine("You wrote the wrong name. Try Again!");
        }
List animalList=new List()//在这里获取动物列表。
if(animalList.Any(x=>x.name==nameInput))
{
}
否则{
Console.WriteLine(“你写错了名字,再试一次!”);
}

我没有看到任何动物列表。。。要将用户输入与动物名称列表进行比较,首先需要有这样一个列表,不是吗?请说明您所做的哪些操作不起作用。如果使用正确,contains和any都应该工作。基本上,动物列表包含保存信息的getter和setter,这是访问的列表:list animalList=new list()@Apollo登陆,
。Any()
都可以。我对编程比较陌生,所以如果你想了解更多信息,请写下来,我会尽力回答
List<Animal> animalList = new List<Animal>(); //Get the animal list here.
        if(animalList.Any(x=>x.name == nameInput))
        {

        }
        else {
         Console.WriteLine("You wrote the wrong name. Try Again!");
        }