Byte.MaxValue 欄位
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示 Byte 最大的可能值。 這個欄位為常數。
public: System::Byte MaxValue = 255;
public const byte MaxValue = 255;
val mutable MaxValue : byte
Public Const MaxValue As Byte = 255
欄位值
Value = 255範例
下列範例示範如何使用 MaxValue 欄位來篩選可能位元組值範圍以外的值變數輸入。
public:
void MinMaxFields( Int32 numberToSet )
{
if ( numberToSet <= (Int32)Byte::MaxValue && numberToSet >= (Int32)Byte::MinValue )
{
// You must explicitly convert an integer to a byte.
MemberByte = (Byte)numberToSet;
// Displays MemberByte using the ToString() method.
Console::WriteLine( "The MemberByte value is {0}", MemberByte.ToString() );
}
else
{
Console::WriteLine( "The value {0} is outside of the range of possible Byte values", numberToSet.ToString() );
}
}
public void MinMaxFields(int numberToSet)
{
if(numberToSet <= (int)Byte.MaxValue && numberToSet >= (int)Byte.MinValue)
{
// You must explicitly convert an integer to a byte.
MemberByte = (Byte)numberToSet;
// Displays MemberByte using the ToString() method.
Console.WriteLine("The MemberByte value is {0}", MemberByte.ToString());
}
else
{
Console.WriteLine("The value {0} is outside of the range of possible Byte values", numberToSet.ToString());
}
}
let minMaxFields numberToSet =
if numberToSet <= int Byte.MaxValue && numberToSet >= int Byte.MinValue then
// You must explicitly convert an integer to a byte.
let myByte = byte numberToSet
printfn $"The MemberByte value is {myByte}"
else
printfn $"The value {numberToSet} is outside of the range of possible Byte values"
Public Sub MinMaxFields(ByVal numberToSet As Integer)
If numberToSet <= CInt([Byte].MaxValue) And numberToSet >= CInt([Byte].MinValue) Then
' You must explicitly convert an integer to a byte.
MemberByte = CType(numberToSet, [Byte])
' Displays MemberByte using the ToString() method.
Console.WriteLine("The MemberByte value is {0}.", MemberByte.ToString())
Else
Console.WriteLine("The value {0} is outside of the range of possible Byte values.", numberToSet.ToString())
End If
End Sub
備註
這個常數的值是 255 (十六進位0xFF) 。