Why is `-lt` behaving differently for chars and strings?

后端 未结 2 1563
盖世英雄少女心
盖世英雄少女心 2020-12-16 05:19

I recently answered a SO-question about using -lt or -gt with strings. My answer was based on something I\'ve read earlier which said that -l

2条回答
  •  一向
    一向 (楼主)
    2020-12-16 05:34

    Not quite sure what to post here other than the comparisons are all correct when dealing with strings/characters. If you want an Ordinal comparison, do an Ordinal comparison and you get results based on that.

    Best Practices for Using Strings in the .NET Framework

    [string]::Compare('L','l')
    returns 1
    

    and

    [string]::Compare("L","l", [stringcomparison]::Ordinal)
    returns -32
    

    Not sure what to add here to help clarify.

    Also see: Upper vs Lower Case

提交回复
热议问题