linq and string.compare/string.equals in wcf?

本文关键字:string in wcf equals and compare linq | 更新日期: 2023-09-27 18:30:58

我有以下方法,我想尝试在字符串中添加。

public List<Group> GetStudentCollectionByGroup(string anything)
{
    List<Group> groups = (from g in Groups
                          where 
                              (from t in g.Groupsz 
                              where t.StudentID == anything 
                                 || t.FirstName == anything 
                                 || t.LastName == anything select t).Count() > 0
                 select g).ToList();
        return groups;
    }

如果我尝试!=而不是在客户端==我在文本框中键入的任何内容,无论键入什么,我都会以某种方式返回组。如果我使用 ==它只会返回与我键入的内容关联的组(当然属于该学生),所以我希望 String.Compare 可能会有所帮助,我只是不知道如何使用它构建上面的代码?

linq and string.compare/string.equals in wcf?

如果您将==替换为!=则您说"返回任何具有anything以外的学生ID或anything以外的名字或anything以外的姓氏的任何t",唯一可能失败的记录将是(anything, anything, anything)

你想要的是一个不区分大小写的比较。

string.Equals(t.FirstName, anything, StringComparision.CurrentCultureIgnoreCase);