首页 > 解决方案 > How to user SingleOrDefault with different string letter case?

问题描述

This is for the intranet. When I search for the username it comes out with lower case.

When I search for the username within the table it never finds the username because it seems it needs to be capitalized as it is also capitalized in the table.

Is there a way to make this work to work on any case when searching the table using SingleOrDefault?

var userNamenew = userName.Split('\\')[1]; //this equals to 'namel'
//var userNamenew = "NameL"; //this work
var CurrentUser = employee.SingleOrDefault(x => x.UserName == userNamenew);

标签: c#asp.netasp.net-mvc

解决方案


What about

employee.SingleOrDefault(x => x.UserName.ToLower() == userNamenew.ToLower());

And then you're comparing two lower case strings


推荐阅读