Int16结构表示一个16位带符号整数,其值范围从负32768到正32767。
以下是Int16的字段-
序号 | 栏位说明 |
---|---|
1 | MaxValue的 - 代表一个Int16类型的最大可能值。该字段是恒定的。 |
2 | MINVALUE - 代表一个Int16类型的最小可能值。该字段是恒定的。 |
以下是一些方法-
序号 | 方法与说明 |
---|---|
1 | CompareTo(Int16) -将实例与指定的16位带符号整数进行比较,并返回一个整数,该整数指示此实例的值是否小于,等于或大于指定的16位带符号整数的值。 |
2 | CompareTo(Object) -将实例与指定对象进行比较,并返回一个整数,该整数指示该实例的值是小于,等于还是大于对象的值。 |
3 | Equals(Int16) - 返回一个值,该值指示此实例是否等于指定的Int16值。 |
4 | Equals(Object) - 返回一个值,该值指示此实例是否等于指定的对象。 |
5 | GetHashCode() - 返回此实例的哈希码。 |
6 | GetTypeCode() - 返回值类型Int16的TypeCode。 |
7 | Parse(String) - 将数字的字符串表示形式转换为其等效的16位带符号整数。 |
现在让我们看看Int16结构的一些示例-
C#中的Int16.GetHashCode()方法用于返回当前实例的哈希码。
public override int GetHashCode ();
现在让我们看一个实现Int16.GetHashCode()方法的示例-
using System; public class Demo { public static void Main() { short val1 = 20; short val2 = 25; 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))); } }
输出结果
这将产生以下输出-
Value1 = 20 Value2 = 25 HashCode for value1 = 1310740 HashCode for value2 = 1638425 Are they equal? = False
现在让我们来看另一个实现Int16.GetHashCode()方法的示例-
using System; public class Demo { public static void Main() { short val1 = 0; short val2 = Int16.MaxValue; 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))); } }
输出结果
这将产生以下输出-
Value1 = 0 Value2 = 32767 HashCode for value1 = 0 HashCode for value2 = 2147450879 Are they equal? = False
C#中的Int16.GetTypeCode()方法用于返回值类型Int16的TypeCode。
public TypeCode GetTypeCode ();
现在让我们看一个实现Int16.GetTypeCode()方法的示例-
using System; public class Demo { public static void Main() { short val1 = 0; short val2 = Int16.MaxValue; 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); } }
输出结果
这将产生以下输出-
Value1 = 0 Value2 = 32767 HashCode for value1 = 0 HashCode for value2 = 2147450879 Are they equal? = False TypeCode for val1 = Int16 TypeCode for val2 = Int16
现在让我们来看另一个实现Int16.GetTypeCode()方法的示例-
using System; public class Demo { public static void Main() { short val1 = 23; short 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); } }
输出结果
这将产生以下输出-
Value1 = 23 Value2 = 0 HashCode for value1 = 1507351 HashCode for value2 = 0 Are they equal? = False TypeCode for val1 = Int16 TypeCode for val2 = Int16