C#中的SByte.ToString()方法与示例
C#中的SByte.ToString()方法用于将该实例的数值转换为其等效的字符串表示形式。
语法
语法如下-
public override string ToString ();
示例
现在让我们看一个例子-
using System;
public class Demo {
public static void Main(){
sbyte s1 = 10;
sbyte s2 = 100;
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");
Console.WriteLine("\nHashCode for s1 = "+s1.GetHashCode());
Console.WriteLine("GetTypeCode for s1 = "+s1.GetTypeCode());
Console.WriteLine("String representation for s1 = "+s1.ToString());
Console.WriteLine("\nHashCode for s2 = "+s2.GetHashCode());
Console.WriteLine("GetTypeCode for s2 = "+s2.GetTypeCode());
Console.WriteLine("String representation for s2 = "+s2.ToString());
}
}输出结果
这将产生以下输出-
Value of S1 = 10 Value of S2 = 100 s1 − s2 HashCode for s1 = 2570 GetTypeCode for s1 = SByte String representation for s1 = 10 HashCode for s2 = 25700 GetTypeCode for s2 = SByte String representation for s2 = 100
示例
现在让我们来看另一个示例-
using System;
public class Demo {
public static void Main(){
sbyte s1 = 99;
sbyte s2 = SByte.MaxValue;
Console.WriteLine("Value of S1 = "+s1);
Console.WriteLine("Value of S2 = "+s2);
Console.WriteLine("Is s1 and s2 equal? = "+s1.Equals(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");
Console.WriteLine("String representation for s1 = "+s1.ToString());
Console.WriteLine("String representation for s2 = "+s2.ToString());
}
}输出结果
这将产生以下输出-
Value of S1 = 99 Value of S2 = 127 Is s1 and s2 equal? = False s1 < s2 String representation for s1 = 99 String representation for s2 = 127
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短