Skip to content

String IgnoreCase extension method #30626

Closed

Description

@BluePositive

How about to split the Equals String extension method in 2 Equals() and EqualsIgnoreCase()
each should a have a default behavior and accepts a new Comparison Enum like the StringComparison Enum that has only 3 values

  1. CurrentCulture
  2. InvariantCulture
  3. Ordinal

as a parameter (like Equals() now)
I think it will make it easier to use for most cases (and more likely to be noticed with an IDE )

Activity

  1. Gnbrkm41 commented on Aug 20, 2019

    @Gnbrkm41
    Contributor
  2. Gnbrkm41 commented on Aug 20, 2019

    @Gnbrkm41
    Contributor

    I don't understand what you mean by "you can alter it by passing a StringComparison Enum". Does that mean that your proposed EqualsIgnoreCase should accept StringComparison as the second parameter? at that point might as well as just use the existing Equals method.

  3. BluePositive commented on Aug 21, 2019

    @BluePositive
    Author

    @Gnbrkm41 I edited the title to make it more understandable.

  4. Gnbrkm41 commented on Aug 22, 2019

    @Gnbrkm41
    Contributor

    So, are you suggesting that your suggestion would be used like:

    str1.EqualsIgnoreCase(str2, StringComparison.Ordinal)

    and it's better than

    str1.Equals(str2, StringComparison.OrdinalIgnoreCase)

    ?

  5. BluePositive commented on Aug 22, 2019

    @BluePositive
    Author

    @Gnbrkm41 in most cases it will be

    str1.EqualsIgnoreCase(str2)

    and that is more straightforward than

    str1.Equals(str2, StringComparison.OrdinalIgnoreCase)
  6. Gnbrkm41 commented on Aug 24, 2019

    @Gnbrkm41
    Contributor
    1. Why does this has to be an extension method? might as well as add it as an instance method if it's going to be useful for discoverability.

    2. I think there's a potential concern with the default culture; every other instance methods (e.g. IndexOf, Compare etc...) use current culture when not specified. This suggestion does not however and use Ordinal, and this would break the tradition of defaulting to culture sensitive comparison. Unless people read the documents (which usually people don't), they would assume that this is culture sensitive, case insensitive comparison. Apparently I was thinking that string.Equals(string) defaults to current culture when its not. 😅

    1. If it's expected to be used without the second parameter for the most case, why bother providing one at all? I think we could just have EqualsIgnoreCase(string) one. It seems rather weird to be able to also specify case insensitivity by StringComparison. (e.g. str1.EqualsIgnorecase(str2, StringComparison.OrdinalIgnoreCase)

    p.s: if we're going to add this as an instance method, I think #14065 suits better.

  7. BluePositive commented on Sep 3, 2019

    @BluePositive
    Author

    @Gnbrkm41

    1. You're right it does not need to be an extension method.
    2. About your issue about the second parameter, my suggestion is that it shouldn't need the second
      parameter only if you want to change the default.
    3. About your issue with passing a StringComparison.OrdinalIgnoreCase I edit the issue to create a new enum that accepts only 3 values without the IgnoreCase values
  8. transferred this issue fromdotnet/corefxon Feb 1, 2020
  9. added this to the Future milestone on Feb 1, 2020
  10. added
    untriaged
    on Feb 23, 2020
  11. added
    api-needs-work
    and removed
    untriaged
    on Jul 2, 2020
  12. removed
    api-suggestion
    on Jun 25, 2021
  13. dotnet-policy-service commented on Dec 25, 2025

    @dotnet-policy-service
    Contributor

    Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

    This process is part of our issue cleanup automation.

  14. added
    backlog-cleanup-candidate
    on Dec 25, 2025
  15. dotnet-policy-service commented on Jan 8, 2026

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  16. removed this from the Future milestone on Jan 8, 2026
  17. locked and limited conversation to collaborators on Feb 7, 2026
  18. removed
    backlog-cleanup-candidate
    on Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-needs-workarea-System.Runtime

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions