patterncsharpCritical
Comparing two strings, ignoring case in C#
Viewed 0 times
twoignoringstringscasecomparing
Problem
Which of the following two is more efficient? (Or maybe is there a third option that's better still?)
OR
?
string val = "AStringValue";
if (val.Equals("astringvalue", StringComparison.InvariantCultureIgnoreCase))OR
if (val.ToLowerCase() == "astringvalue")?
Solution
The first one is the correct one, and IMHO the more efficient one, since the second 'solution' instantiates a new string instance.
Context
Stack Overflow Q#6371150, score: 222
Revisions (0)
No revisions yet.