Framework Fundamentals - String - Comparing Strings

  • In comparing two values, the .NET Framework differentiates the concepts of equality comparison and order comparison.
  • Equality comparison tests whether two instances are semantically the same.
  • Order comparison tests which of two (if any) instances comes first when arranging them in ascending or descending sequence.
  • For string Equality comparison, you can use the
    • == Operator
    • string.Equals() static method as will as instance method, this option is better because they allow you to specify options such as case-sentitvity/culture-sensitivity.
  • For string Order comparison, you can use the
    • CompareTo() instance method
    • string.Compare() static method
    • stirng.CompareOrdinal() static method
    • The return values of above said methods will be
      • 0 for equal
      • 1 if first value comes before second value
      • 2 if second value comes before first value
  •  

No comments:

Post a Comment

Framework Fundamentals - String - Comparing Strings

In comparing two values, the .NET Framework differentiates the concepts of equality comparison and order comparison . Equality compariso...