Math.Sign Methode
Definition
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Zahl angibt.Returns an integer that indicates the sign of a number.
Überlädt
Sign(Single) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Gleitkommazahl mit einfacher Genauigkeit angibt.Returns an integer that indicates the sign of a single-precision floating-point number. |
Sign(SByte) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 8-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of an 8-bit signed integer. |
Sign(Int32) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 32-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 32-bit signed integer. |
Sign(Int64) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 64-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 64-bit signed integer. |
Sign(Double) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Gleitkommazahl mit doppelter Genauigkeit angibt.Returns an integer that indicates the sign of a double-precision floating-point number. |
Sign(Decimal) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Dezimalzahl angibt.Returns an integer that indicates the sign of a decimal number. |
Sign(Int16) |
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 16-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 16-bit signed integer. |
Sign(Single)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Gleitkommazahl mit einfacher Genauigkeit angibt.Returns an integer that indicates the sign of a single-precision floating-point number.
public:
static int Sign(float value);
public static int Sign (float value);
static member Sign : single -> int
Public Shared Function Sign (value As Single) As Integer
Parameter
- value
- Single
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Ausnahmen
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Single) -Methode verwendet wird, um das Single Vorzeichen eines Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Single) method to determine the sign of a Single value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(SByte)
Wichtig
Diese API ist nicht CLS-kompatibel.
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 8-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of an 8-bit signed integer.
public:
static int Sign(System::SByte value);
[System.CLSCompliant(false)]
public static int Sign (sbyte value);
static member Sign : sbyte -> int
Public Shared Function Sign (value As SByte) As Integer
Parameter
- value
- SByte
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
- Attribute
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(SByte) -Methode verwendet wird, um das SByte Vorzeichen eines-Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(SByte) method to determine the sign of an SByte value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(Int32)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 32-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 32-bit signed integer.
public:
static int Sign(int value);
public static int Sign (int value);
static member Sign : int -> int
Public Shared Function Sign (value As Integer) As Integer
Parameter
- value
- Int32
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Int32) -Methode verwendet wird, um das Int32 Vorzeichen eines-Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Int32) method to determine the sign of an Int32 value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(Int64)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 64-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 64-bit signed integer.
public:
static int Sign(long value);
public static int Sign (long value);
static member Sign : int64 -> int
Public Shared Function Sign (value As Long) As Integer
Parameter
- value
- Int64
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Int64) -Methode verwendet wird, um das Int64 Vorzeichen eines-Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Int64) method to determine the sign of an Int64 value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(Double)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Gleitkommazahl mit doppelter Genauigkeit angibt.Returns an integer that indicates the sign of a double-precision floating-point number.
public:
static int Sign(double value);
public static int Sign (double value);
static member Sign : double -> int
Public Shared Function Sign (value As Double) As Integer
Parameter
- value
- Double
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Ausnahmen
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Double) -Methode verwendet wird, um das Double Vorzeichen eines Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Double) method to determine the sign of a Double value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(Decimal)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer Dezimalzahl angibt.Returns an integer that indicates the sign of a decimal number.
public:
static int Sign(System::Decimal value);
public static int Sign (decimal value);
static member Sign : decimal -> int
Public Shared Function Sign (value As Decimal) As Integer
Parameter
- value
- Decimal
Eine Dezimalzahl mit Vorzeichen.A signed decimal number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Decimal) -Methode verwendet wird, um das Decimal Vorzeichen eines Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Decimal) method to determine the sign of a Decimal value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.
Sign(Int16)
Gibt eine ganze Zahl zurück, die das Vorzeichen einer ganzen 16-Bit-Zahl mit Vorzeichen angibt.Returns an integer that indicates the sign of a 16-bit signed integer.
public:
static int Sign(short value);
public static int Sign (short value);
static member Sign : int16 -> int
Public Shared Function Sign (value As Short) As Integer
Parameter
- value
- Int16
Eine Zahl mit Vorzeichen.A signed number.
Gibt zurück
Eine Zahl, die das Vorzeichen von value
angibt, wie in der folgenden Tabelle veranschaulicht.A number that indicates the sign of value
, as shown in the following table.
RückgabewertReturn value | BedeutungMeaning |
---|---|
-1-1 | value ist kleiner als Null.value is less than zero.
|
00 | value ist gleich 0 (null).value is equal to zero.
|
11 | value ist größer als 0 (null).value is greater than zero.
|
Beispiele
Im folgenden Beispiel wird veranschaulicht, wie die Sign(Int16) -Methode verwendet wird, um das Int16 Vorzeichen eines-Werts zu bestimmen und in der Konsole anzuzeigen.The following example demonstrates how to use the Sign(Int16) method to determine the sign of an Int16 value and display it to the console.
// This example demonstrates Math.Sign()
using namespace System;
String^ Test( int compare )
{
if ( compare == 0 )
return "equal to";
else
if ( compare < 0 )
return "less than";
else
return "greater than";
}
int main()
{
String^ str = "{0}: {1,3} is {2} zero.";
String^ nl = Environment::NewLine;
Byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7;
// The following type is not CLS-compliant.
SByte xSbyte1 = -101;
Console::WriteLine( "{0}Test the sign of the following types of values:", nl );
Console::WriteLine( str, "Byte ", xByte1, Test( Math::Sign( xByte1 ) ) );
Console::WriteLine( str, "Int16 ", xShort1, Test( Math::Sign( xShort1 ) ) );
Console::WriteLine( str, "Int32 ", xInt1, Test( Math::Sign( xInt1 ) ) );
Console::WriteLine( str, "Int64 ", xLong1, Test( Math::Sign( xLong1 ) ) );
Console::WriteLine( str, "Single ", xSingle1, Test( Math::Sign( xSingle1 ) ) );
Console::WriteLine( str, "Double ", xDouble1, Test( Math::Sign( xDouble1 ) ) );
Console::WriteLine( str, "Decimal", xDecimal1, Test( Math::Sign( xDecimal1 ) ) );
//
Console::WriteLine( "{0}The following type is not CLS-compliant.", nl );
Console::WriteLine( str, "SByte ", xSbyte1, Test( Math::Sign( xSbyte1 ) ) );
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
// This example demonstrates Math.Sign()
using System;
class Sample
{
public static void Main()
{
string str = "{0}: {1,3} is {2} zero.";
string nl = Environment.NewLine;
byte xByte1 = 0;
short xShort1 = -2;
int xInt1 = -3;
long xLong1 = -4;
float xSingle1 = 0.0f;
double xDouble1 = 6.0;
Decimal xDecimal1 = -7m;
// The following type is not CLS-compliant.
sbyte xSbyte1 = -101;
Console.WriteLine($"{nl}Test the sign of the following types of values:");
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)));
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)));
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)));
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)));
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)));
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)));
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)));
Console.WriteLine($"{nl}The following type is not CLS-compliant.");
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)));
}
public static string Test(int compare)
{
if (compare == 0)
return "equal to";
else if (compare < 0)
return "less than";
else
return "greater than";
}
}
/*
This example produces the following results:
Test the sign of the following types of values:
Byte : 0 is equal to zero.
Int16 : -2 is less than zero.
Int32 : -3 is less than zero.
Int64 : -4 is less than zero.
Single : 0 is equal to zero.
Double : 6 is greater than zero.
Decimal: -7 is less than zero.
The following type is not CLS-compliant.
SByte : -101 is less than zero.
*/
' This example demonstrates Math.Sign()
Class Sample
Public Shared Sub Main()
Dim str As String = "{0}: {1,3} is {2} zero."
Dim nl As String = Environment.NewLine
Dim xByte1 As Byte = 0
Dim xShort1 As Short = -2
Dim xInt1 As Integer = -3
Dim xLong1 As Long = -4
Dim xSingle1 As Single = 0F
Dim xDouble1 As Double = 6.0
Dim xDecimal1 As [Decimal] = -7D
' The following type is not CLS-compliant.
Dim xSbyte1 As SByte = -101
Console.WriteLine("{0}Test the sign of the following types of values:", nl)
Console.WriteLine(str, "Byte ", xByte1, Test(Math.Sign(xByte1)))
Console.WriteLine(str, "Int16 ", xShort1, Test(Math.Sign(xShort1)))
Console.WriteLine(str, "Int32 ", xInt1, Test(Math.Sign(xInt1)))
Console.WriteLine(str, "Int64 ", xLong1, Test(Math.Sign(xLong1)))
Console.WriteLine(str, "Single ", xSingle1, Test(Math.Sign(xSingle1)))
Console.WriteLine(str, "Double ", xDouble1, Test(Math.Sign(xDouble1)))
Console.WriteLine(str, "Decimal", xDecimal1, Test(Math.Sign(xDecimal1)))
'
Console.WriteLine("{0}The following type is not CLS-compliant.", nl)
Console.WriteLine(str, "SByte ", xSbyte1, Test(Math.Sign(xSbyte1)))
End Sub
'
Public Shared Function Test([compare] As Integer) As [String]
If [compare] = 0 Then
Return "equal to"
ElseIf [compare] < 0 Then
Return "less than"
Else
Return "greater than"
End If
End Function 'Test
End Class
'
'This example produces the following results:
'
'Test the sign of the following types of values:
'Byte : 0 is equal to zero.
'Int16 : -2 is less than zero.
'Int32 : -3 is less than zero.
'Int64 : -4 is less than zero.
'Single : 0 is equal to zero.
'Double : 6 is greater than zero.
'Decimal: -7 is less than zero.
'
'The following type is not CLS-compliant.
'SByte : -101 is less than zero.