list.find和list.Exist总是返回false

时间:2014-08-12 09:51:57

标签: c# find

我有一份usr列表 -

public static List<usr> usersList = new List<usr>();

其中usr定义是 -

public class usr
        {
            public string name;
            public string question;
            public string connID;
        }

当我找到/存在现有的用户时,我总是得到假(不存在), 我用于查找/存在的代码如下 -

bool b = usersList.Exists(x => x.name == name);
usr student = usersList.Find(x => x.name == name);

在查找/存在之前检查usersList时,我可以看到列表中存在usr。

我做错了什么???

1 个答案:

答案 0 :(得分:0)

原因是我在搜索字符串中有空格:(

我今天最好去钓鱼。

谢谢大家的意见。