Skip to content

String.CompareTo Behaviour different between WIN10 & Linux #36177

Closed

Description

@Ninds

Console.WriteLine("[".CompareTo("_"));
On Windows => -1
On Linux => 1

Linux :
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7

Runtime Environment:
OS Name: debian
OS Version: 10
OS Platform: Linux
RID: debian.10-x64

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

Windows :
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

Activity

  1. added
    untriaged
    on May 10, 2020
  2. benaadams commented on May 10, 2020

    @benaadams
    Member

    Different culture between the two? Try using .CompareOrdinal

  3. removed
    untriaged
    on May 10, 2020
  4. tarekgh commented on May 10, 2020

    @tarekgh
    Member

    This is by design for the .NET as we depend on the underlying OS for globalization support. so it is expected to see some behavior differences when running on Windows against Linux. @benaadams suggestion to use ordinal comparison should help if this will be ok in your scenario.

    In .NET Core 5.0, we have started to use the ICU library on Windows too. That means the behavior on Windows and Linux should be the same or very close. You may give it a try.

  5. Ninds commented on May 17, 2020

    @Ninds
    Author

    Cheers. Tweaking the culture indeed yielded the required behaviour.

  6. ghost locked as resolved and limited conversation to collaborators on Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions