SByte.MaxValue 欄位
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 SByte 最大的可能值。 這個欄位為常數。
public: System::SByte MaxValue = 127;
public const sbyte MaxValue = 127;
val mutable MaxValue : sbyte
Public Const MaxValue As SByte = 127
欄位值
Value = 127範例
下列範例會使用 MinValue 和 MaxValue 欄位來驗證 Int64 值在執行類型轉換之前,值是否在類型範圍內 SByte 。 此驗證會在 OverflowException 執行時間防止 。
long longValue = -130;
sbyte byteValue;
if (longValue <= sbyte.MaxValue &&
longValue >= sbyte.MinValue)
{
byteValue = (sbyte) longValue;
Console.WriteLine("Converted long integer value to {0}.", byteValue);
}
else
{
sbyte rangeLimit;
string relationship;
if (longValue > sbyte.MaxValue)
{
rangeLimit = sbyte.MaxValue;
relationship = "greater";
}
else
{
rangeLimit = sbyte.MinValue;
relationship = "less";
}
Console.WriteLine("Conversion failure: {0:n0} is {1} than {2}.",
longValue,
relationship,
rangeLimit);
}
let longValue = -130L
if longValue <= int64 SByte.MaxValue && longValue >= int64 SByte.MinValue then
let byteValue = int8 longValue
printfn $"Converted long integer value to {byteValue}."
else
let rangeLimit, relationship =
if longValue > int64 SByte.MaxValue then
SByte.MaxValue, "greater"
else
SByte.MinValue, "less"
printfn $"Conversion failure: {longValue:n0} is {relationship} than {rangeLimit}."
Dim longValue As Long = -130
Dim byteValue As SByte
If longValue <= SByte.MaxValue AndAlso _
longValue >= SByte.MinValue Then
byteValue = CSByte(longValue)
Console.WriteLine("Converted long integer value to {0}.", byteValue)
Else
Dim rangeLimit As SByte
Dim relationship As String
If longValue > SByte.MaxValue Then
rangeLimit = SByte.MaxValue
relationship = "greater"
Else
rangeLimit = SByte.MinValue
relationship = "less"
End If
Console.WriteLine("Conversion failure: {0:n0} is {1} than {2}.", _
longValue, _
relationship, _
rangeLimit)
End If
備註
這個常數的值是 127;也就是十六進位0x7F。