c# - 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);
解决方案
What about
employee.SingleOrDefault(x => x.UserName.ToLower() == userNamenew.ToLower());
And then you're comparing two lower case strings
推荐阅读
- java - Spring boot zuul错误重定向请求
- docker - 从 docker 容器访问主机扫描仪
- java - Android 构建错误 - MethodHandle.invoke 和 MethodHandle.invokeExact 仅支持从 Android O (--min-api 26) 开始
- windows - 仅隔离输出:FFmpeg
- database - 数据库同步和丢失连接
- javascript - 计算通过选择两点绘制的线与绘制的曲线的距离之间的比率
- c# - 在网络抓取中使用 html 文档和节点与简单的字符串操作相比有什么好处?
- list - 如果结构是列表的一部分,则访问结构字段
- asp.net-mvc - 如何使用 dapper 从存储过程中返回多个结果
- installation - 使用 squirrel.windows 部署 WPF 应用程序,并且在程序和功能中没有 Windows 10 条目