SByte.CompareTo() 方法在 C# 中的使用及示例
在 C# 中,SByte.CompareTo() 方法用于将此实例与指定的 SByte 或者对象进行比较,并返回其相对值指示。
语法
语法如下 −
public int CompareTo (sbyte val); public int CompareTo (object ob);
以上,对于第二个语法,参数值为要比较的 8 位带符号整数,而 ob 则为要比较的对象。
示例
让我们看一个示例 −
using System;
public class Demo {
public static void Main() {
sbyte s1 = 55;
sbyte s2 = 55;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
}
}输出
将生成以下输出 −
Value of S1 = 55 Value of S2 = 55 s1 = s2
示例
下面让我们看另一个示例 −
using System;
public class Demo {
public static void Main() {
sbyte s1 = 55;
object s2 = (sbyte)55;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
int res = s1.CompareTo(s2);
if (res > 0)
Console.WriteLine("s1 > s2");
else if (res < 0)
Console.WriteLine("s1 < s2");
else
Console.WriteLine("s1 = s2");
}
}输出
将生成以下输出 −
Value of S1 = 55 Value of S2 = 55 s1 = s2
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP