Skip to content

Instantly share code, notes, and snippets.

@codehaks
Created Oct 3, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@reza899 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