KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
There are a number of ways to compare strings. Are there performance gains by doing one way over another? I've always opted to compare strings like so: string name = "Bob Wazowski"; if (name.CompareTo("Jill Yearsley") == 0) { // whatever... } But I find few people doing this, and if anything, I see more people just doing a straight == comparison, which to my knowledge is the worst way to compare strings. Am I wrong? Also, does it make a difference in how one compares strings within LINQ queries? For example, I like to do the following: var results = from names in ctx.Names where names.FirstName.CompareTo("Bob Wazowski") == 0 select names; But again, I see few people doing string comparisons like so in their LINQ queries.
Tags (comma-separated)
Save Edits
Cancel