Created
October 3, 2018 08:03
-
-
Save codehaks/9af9139475fce4460f02853e543201dd to your computer and use it in GitHub Desktop.
Comparing Strings in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Compare | |
{ | |
public IActionResult ToLower() | |
{ | |
var all = _db.Users.ToList(); | |
var now = DateTime.Now; | |
int jacksCount = 0; | |
for (int i = 0; i < 1000; i++) | |
{ | |
jacksCount = all.Where(u => u.Givenname.ToLower() == "jack").Count(); | |
} | |
var duration = (DateTime.Now - now).TotalSeconds; | |
return Ok(jacksCount.ToString() + " , Time : " + duration); | |
} | |
public IActionResult Equal() | |
{ | |
var all = _db.Users.ToList(); | |
var now = DateTime.Now; | |
int jacksCount = 0; | |
for (int i = 0; i < 1000; i++) | |
{ | |
jacksCount = all.Where(u => string.Equals(u.Givenname, "jack", StringComparison.OrdinalIgnoreCase)).Count(); | |
} | |
var duration = (DateTime.Now - now).TotalSeconds; | |
return Ok(jacksCount + " , Time : " + duration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great tip! thx