From the course: C#: String Essential Training

Unlock the full course today

Join today to access over 24,000 courses taught by industry experts.

How string comparison works in .NET

How string comparison works in .NET - C# Tutorial

From the course: C#: String Essential Training

How string comparison works in .NET

- [Instructor] Comparing strings is a common task in programming. We compare strings to answer one of two questions. We compare for equality to answer the question, are these strings equal or identical? We compare for sorting purposes to answer another question, in what order should these strings be placed when sorting them? To perform a test for equality, use the String.Equals method. It compares two strings and returns a Boolean indicating whether they are equal. The Compare method is meant to determine the sort order of strings. It takes two string parameters and returns an integer indicating the sort order. This is a simplistic view and it's more nuanced than what's on the slide but it's enough details for the moment. There are additional considerations that influence string comparisons. For example, is it important to check for an exact match with each string character? In other words, is every Unicode character…

Contents