UInt16.MinValue 字段在 C# 中应用的示例
C# 中的 UInt16.MinValue 字段表示 16 位无符号整数的最小可能值。
语法
以下是语法 −
public const ushort MinValue = 0;
示例
现在让我们看看一个示例以实现 UInt16.MinValue 字段 −
using System; public class Demo { public static void Main(){ ushort val1 = 23; ushort val2 = 0; Console.WriteLine("Value1 = "+val1); Console.WriteLine("Value2 = "+val2); Console.WriteLine("HashCode for value1 = "+val1.GetHashCode()); Console.WriteLine("HashCode for value2 = "+val2.GetHashCode()); Console.WriteLine("Are they equal? = "+(val1.Equals(val2))); TypeCode type1 = val1.GetTypeCode(); TypeCode type2 = val2.GetTypeCode(); Console.WriteLine("TypeCode for val1 = "+type1); Console.WriteLine("TypeCode for val2 = "+type2); Console.WriteLine("Minimum Value = "+ UInt16.MinValue); } }
输出
这将产生以下输出 −
Value1 = 23 Value2 = 0 HashCode for value1 = 23 HashCode for value2 = 0 Are they equal? = False TypeCode for val1 = UInt16 TypeCode for val2 = UInt16 Minimum Value = 0
示例
现在让我们看看另一个示例以实现 UInt16.MinValue 字段 −
using System; public class Demo { public static void Main(){ ulong[]val = {8998, 899898778, 878787878}; ushort res; foreach(ulong a in val){ if(a >= UInt16.MinValue && a <= UInt16.MaxValue){ res = Convert.ToUInt16(a); Console.WriteLine("Converted: "+res); } else { Console.WriteLine("Not Possible"); } } } }
输出
这将产生以下输出 −
Converted: 8998 Not Possible Not Possible
广告