+92 332 4229 857 99ProjectIdeas@Gmail.com

String Equals Function (C#.net)














Determine whether two specified string objects have same value or not?

1.     string strOne = "Osama";
2.     string strTwo = "Maverick";
3.  MessageBox.Show(string.Equals(strOne, strTwo).ToString());

Or we can write:
1.     bool result = string.Equals(strOne, strTwo);
2.     MessageBox.Show(result.ToString());
  
Output:
False (Because they are not Equals)

Determines whether two specified string objects are equal ignoring their case:

1.     string strOne = "Osama";
2.     string strTwo = "OSAMA";
3.     bool result = string.Equals(strOne, strTwo);
4.     MessageBox.Show(result.ToString());

Output:
False (Because they are not Equal)

But if you write like this:
1.     string strOne = "Osama";
2.     string strTwo = "OSAMA";
3.     bool result = string.Equals(strOne,strTwo,StringComparison.CurrentCultureIgnoreCase);
4.     MessageBox.Show(result.ToString());

Output:
True (Because they are Equal and ignores capital or small letter case)

0 comments: