1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Compare Toの戻り値について

Last updated at Posted at 2019-10-29

CompareToは
左-右という風に覚えたらいい。

実行した結果は3パターンしかない。

  • 1
  • -1
  • 0

のどれかになる。


 string num1 = "50";
 string num2 = "60";

 var result = num1.Compare(num2);
 System.Console.WriteLine(result);

結果 -1

 var result = num2.Compare(num1);
 System.Console.WriteLine(result);

結果 1

  • 文字列は文字コードで大きさが決まっている。
"a".Compare("b");

結果は-1

z>y>x .....a

1
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?