Skip to content

Instantly share code, notes, and snippets.

@codehaks
Created October 3, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehaks/9af9139475fce4460f02853e543201dd to your computer and use it in GitHub Desktop.
Save codehaks/9af9139475fce4460f02853e543201dd to your computer and use it in GitHub Desktop.
Comparing Strings in C#
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);
}
}
@reza899
Copy link

reza899 commented Jul 13, 2019

great tip! thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment