Languages
[Edit]
EN

C# / .NET - compare strings

9 points
Created by:
Flimzy
596

In this short article, we would like to show how to compare strings in C#.

Quick solution:

Use Equals() mehod for safety.

Practical example: 

 

Trouble shooting

Edit

When we use == operator to compare strings, there is used == operator defined in String class. To compare objects we should use Equals() method.

So, the below source code, comparision returns true value:

But, for the changed source code, comparision returns false value:

It is caused by: how x and y variables are stored and what type have.

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join