
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
C# Int16 Struct
The Int16 Struct represents a 16-bit signed integer with values ranging from negative 32768 through positive 32767.
Following are the fields of Int16 −
Sr.No | Field & Description |
---|---|
1 | MaxValue − Represents the largest possible value of an Int16. This field is constant. |
2 | MinValue − Represents the smallest possible value of an Int16. This field is constant. |
Following are some of the methods −
Sr.No | Method & Description |
---|---|
1 | CompareTo(Int16) − Compares this instance to a specified 16-bit signed integer and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified 16-bit signed integer. |
2 | CompareTo(Object) − Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the object. |
3 | Equals(Int16) − Returns a value indicating whether this instance is equal to a specified Int16 value. |
4 | Equals(Object) − Returns a value indicating whether this instance is equal to a specified object. |
5 | GetHashCode() − Returns the hash code for this instance. |
6 | GetTypeCode() − Returns the TypeCode for value type Int16. |
7 | Parse(String) − Converts the string representation of a number to its 16-bit signed integer equivalent. |
Let us now see some examples of the Int16 Struct −
The Int16.GetHashCode() method in C# is used to return the hash code for the current instance.
Syntax
public override int GetHashCode ();
Example
Let us now see an example to implement the Int16.GetHashCode() method −
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))); } }
Output
This will produce the following output −
Value1 = 20 Value2 = 25 HashCode for value1 = 1310740 HashCode for value2 = 1638425 Are they equal? = False
Example
Let us now see another example to implement the Int16.GetHashCode() method −
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))); } }
Output
This will produce the following output −
Value1 = 0 Value2 = 32767 HashCode for value1 = 0 HashCode for value2 = 2147450879 Are they equal? = False
The Int16.GetTypeCode() method in C# is used to return the TypeCode for value type Int16.
Syntax
public TypeCode GetTypeCode ();
Example
Let us now see an example to implement the Int16.GetTypeCode() method −
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); } }
Output
This will produce the following output −
Value1 = 0 Value2 = 32767 HashCode for value1 = 0 HashCode for value2 = 2147450879 Are they equal? = False TypeCode for val1 = Int16 TypeCode for val2 = Int16
Example
Let us now see another example to implement the Int16.GetTypeCode() method −
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); } }
Output
This will produce the following output −
Value1 = 23 Value2 = 0 HashCode for value1 = 1507351 HashCode for value2 = 0 Are they equal? = False TypeCode for val1 = Int16 TypeCode for val2 = Int16
- Related Articles
- C# Int16.ToString() Method
- Int16.CompareTo() Method in C#
- C# Int32 Struct
- C/C++ Struct vs Class
- UInt16 Struct in C#
- UInt32 Struct in C#
- Char Struct in C#
- Byte Struct in C#
- UInt64 Struct in C#
- Decimal Struct in C#
- Int16.Equals Method in C# with Examples
- Int16.GetHashCode() Method in C# with Examples
- Int16.GetTypeCode Method in C# with Examples
- Int16.MaxValue Field in C# with Examples
- Int16.MinValue Field in C# with Examples
