Freigeben über


Decimal.GetHashCode Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the hash code for this instance.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Overrides Function GetHashCode As Integer
[SecuritySafeCriticalAttribute]
public override int GetHashCode()

Return Value

Type: System.Int32
A 32-bit signed integer hash code.

Examples

The following code example uses the GetHashCode method to return the hash codes of several Decimal values.

' Example of the Decimal.GetHashCode method. 

Module Example

   ' Display the Decimal.GetHashCode argument and the result array.
   Sub ShowDecimalGetHashCode(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal Argument As Decimal)

      Dim hashCode As Integer = Argument.GetHashCode()

      outputBlock.Text &= "{0,31}{1,14}  0x{1:X8}", Argument, _
          hashCode & vbCrLf
   End Sub

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= "This example of the " & _
          "Decimal.GetHashCode( ) method generates " & vbCrLf & _
          "the following output. It displays the hash code of " & _
          "the " & vbCrLf & "Decimal argument in decimal and " & _
          "hexadecimal." & vbCrLf & vbCrLf
      outputBlock.Text &= String.Format("{0,31}{1,14}", "Argument", "Hash Code") & vbCrLf
      outputBlock.Text &= String.Format("{0,31}{1,14}", "--------", "---------") & vbCrLf

      ' Generate hash codes for Decimal objects.
      ShowDecimalGetHashCode(outputBlock, 0D)
      ShowDecimalGetHashCode(outputBlock, 1D)
      ShowDecimalGetHashCode(outputBlock,  _
          Decimal.Parse("1.0000000000000000000000000000"))
      ShowDecimalGetHashCode(outputBlock, 100000000000000D)
      ShowDecimalGetHashCode(outputBlock,  _
          Decimal.Parse("100000000000000.00000000000000"))
      ShowDecimalGetHashCode(outputBlock, 10000000000000000000000000000D)
      ShowDecimalGetHashCode(outputBlock, 10000000000000000000000009999D)
      ShowDecimalGetHashCode(outputBlock, 10000000000000000004294967295D)
      ShowDecimalGetHashCode(outputBlock, 123456789D)
      ShowDecimalGetHashCode(outputBlock, 0.123456789D)
      ShowDecimalGetHashCode(outputBlock, 0.000000000123456789D)
      ShowDecimalGetHashCode(outputBlock, 0.000000000000000000123456789D)
      ShowDecimalGetHashCode(outputBlock, 4294967295D)
      ShowDecimalGetHashCode(outputBlock, 18446744073709551615D)
      ShowDecimalGetHashCode(outputBlock, Decimal.MaxValue)
      ShowDecimalGetHashCode(outputBlock, Decimal.MinValue)
      ShowDecimalGetHashCode(outputBlock, -7.9228162514264337593543950335D)
   End Sub
End Module

' This example of the Decimal.GetHashCode( ) method generates
' the following output. It displays the hash code of the
' Decimal argument in decimal and hexadecimal.
' 
'                        Argument     Hash Code
'                        --------     ---------
'                               0             0  0x00000000
'                               1    1072693248  0x3FF00000
'  1.0000000000000000000000000000    1072693248  0x3FF00000
'                 100000000000000    1548139716  0x5C46BCC4
'  100000000000000.00000000000000    1548139716  0x5C46BCC4
'   10000000000000000000000000000    1793013094  0x6ADF3566
'   10000000000000000000000009999    1793013094  0x6ADF3566
'   10000000000000000004294967295    1793013094  0x6ADF3566
'                       123456789     362639156  0x159D6F34
'                     0.123456789     143063426  0x0886F982
'            0.000000000123456789    -667156908  0xD83BFE54
'   0.000000000000000000123456789    -261016360  0xF07134D8
'                      4294967295   -1106247681  0xBE0FFFFF
'            18446744073709551615    1139802112  0x43F00000
'   79228162514264337593543950335    1173356544  0x45F00000
'  -79228162514264337593543950335    -974127104  0xC5F00000
' -7.9228162514264337593543950335    2119160044  0x7E4FD0EC
// Example of the decimal.GetHashCode method. 
using System;

class Example
{
   // Display the decimal.GetHashCode argument and the result array.
   public static void ShowDecimalGetHashCode(System.Windows.Controls.TextBlock outputBlock, decimal Argument)
   {
      int hashCode = Argument.GetHashCode();

      outputBlock.Text += "{0,31}{1,14}  0x{1:X8}",
          Argument, hashCode + "\n";
   }

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "This example of the " +
          "decimal.GetHashCode( ) method generates \nthe " +
          "following output. It displays the hash code of the \n" +
          "decimal argument in decimal and hexadecimal.\n" + "\n";
      outputBlock.Text += String.Format("{0,31}{1,14}", "Argument", "Hash Code") + "\n";
      outputBlock.Text += String.Format("{0,31}{1,14}", "--------", "---------") + "\n";

      // Generate hash codes for decimal objects.
      ShowDecimalGetHashCode(outputBlock, 0M);
      ShowDecimalGetHashCode(outputBlock, 1M);
      ShowDecimalGetHashCode(outputBlock, 1.0000000000000000000000000000M);
      ShowDecimalGetHashCode(outputBlock, 100000000000000M);
      ShowDecimalGetHashCode(outputBlock, 100000000000000.00000000000000M);
      ShowDecimalGetHashCode(outputBlock, 10000000000000000000000000000M);
      ShowDecimalGetHashCode(outputBlock, 10000000000000000000000009999M);
      ShowDecimalGetHashCode(outputBlock, 10000000000000000004294967295M);
      ShowDecimalGetHashCode(outputBlock, 123456789M);
      ShowDecimalGetHashCode(outputBlock, 0.123456789M);
      ShowDecimalGetHashCode(outputBlock, 0.000000000123456789M);
      ShowDecimalGetHashCode(outputBlock, 0.000000000000000000123456789M);
      ShowDecimalGetHashCode(outputBlock, 4294967295M);
      ShowDecimalGetHashCode(outputBlock, 18446744073709551615M);
      ShowDecimalGetHashCode(outputBlock, decimal.MaxValue);
      ShowDecimalGetHashCode(outputBlock, decimal.MinValue);
      ShowDecimalGetHashCode(outputBlock, -7.9228162514264337593543950335M);
   }
}

/*
This example of the decimal.GetHashCode( ) method generates
the following output. It displays the hash code of the
decimal argument in decimal and hexadecimal.

                       Argument     Hash Code
                       --------     ---------
                              0             0  0x00000000
                              1    1072693248  0x3FF00000
 1.0000000000000000000000000000    1072693248  0x3FF00000
                100000000000000    1548139716  0x5C46BCC4
 100000000000000.00000000000000    1548139716  0x5C46BCC4
  10000000000000000000000000000    1793013094  0x6ADF3566
  10000000000000000000000009999    1793013094  0x6ADF3566
  10000000000000000004294967295    1793013094  0x6ADF3566
                      123456789     362639156  0x159D6F34
                    0.123456789     143063426  0x0886F982
           0.000000000123456789    -667156908  0xD83BFE54
  0.000000000000000000123456789    -261016360  0xF07134D8
                     4294967295   -1106247681  0xBE0FFFFF
           18446744073709551615    1139802112  0x43F00000
  79228162514264337593543950335    1173356544  0x45F00000
 -79228162514264337593543950335    -974127104  0xC5F00000
-7.9228162514264337593543950335    2119160044  0x7E4FD0EC
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference