C#中的UInt16.ToString方法与示例
C#中的UInt16.ToString()方法用于将当前UInt16实例的数值转换为其等效的字符串表示形式。
语法
以下是语法-
public override string ToString();
示例
现在让我们看一个实现UInt16.ToString()方法的示例-
using System;
public class Demo {
public static void Main(){
ushort val1 = 100;
ushort val2 = 80;
Console.WriteLine("Value1 (String representation) = "+val1.ToString());
Console.WriteLine("Value2 (String representation) = "+val2.ToString());
bool res = val1.Equals(val2);
Console.WriteLine("Return value (comparison) = "+res);
if (res)
Console.WriteLine("val1 = val2");
else
Console.WriteLine("val1 != val2");
}
}输出结果
这将产生以下输出-
Value1 (String representation) = 100 Value2 (String representation) = 80 Return value (comparison) = False val1 != val2
示例
现在让我们来看另一个实现UInt16.ToString()方法的示例-
using System;
public class Demo {
public static void Main(){
ushort val1 = 0;
ushort val2 = UInt16.MaxValue;
Console.WriteLine("Value1 (String representation) = "+val1.ToString());
Console.WriteLine("Value2 (String representation) = "+val2.ToString());
bool res = val1.Equals(val2);
Console.WriteLine("Return value (comparison) = "+res);
if (res)
Console.WriteLine("val1 = val2");
else
Console.WriteLine("val1 != val2");
}
}输出结果
这将产生以下输出-
Value1 (String representation) = 0 Value2 (String representation) = 65535 Return value (comparison) = False val1 != val2
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短