Assembly : mscorlib (dans mscorlib.dll)
Syntaxe<SerializableAttribute> _ <ComVisibleAttribute(True)> _ Public Structure Byte Implements IComparable, IFormattable, IConvertible, IComparable(Of Byte), _ IEquatable(Of Byte)
Dim instance As Byte
[SerializableAttribute] [ComVisibleAttribute(true)] public struct Byte : IComparable, IFormattable, IConvertible, IComparable<byte>, IEquatable<byte>
[SerializableAttribute] [ComVisibleAttribute(true)] public value class Byte : IComparable, IFormattable, IConvertible, IComparable<unsigned char>, IEquatable<unsigned char>
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public final class Byte extends ValueType implements IComparable, IFormattable, IConvertible, IComparable<byte>, IEquatable<byte>
JScript prend en charge l'utilisation de structures mais pas la déclaration de nouvelles structures.
NotesLe type valeur Byte représente des entiers non signés dont la valeur est comprise entre 0 et 255.
Byte fournit les méthodes permettant de comparer les instances de ce type, de convertir la valeur d'une instance en sa représentation sous forme de chaîne et de convertir la représentation sous forme de chaîne d'un nombre en instance de ce type.
Pour plus d'informations sur la façon dont les codes de spécification de format contrôlent les chaînes de types valeur, consultez Vue d'ensemble des formats.
Ce type implémente les interfaces IComparable, IComparable, IFormattable et IConvertible. Pour les conversions, utilisez la classe Convert au lieu de l'implémentation du membre d'interface explicite de IConvertible de ce type.
Ce type est thread-safe ; plusieurs threads peuvent procéder à une lecture simultanée à partir d'une instance de ce type.
ExempleL'exemple suivant illustre l'utilisation de Byte lors de la conversion d'un tableau d'octets en chaîne de valeurs hexadécimales.
Class HexTest Private Shared hexDigits As Char() = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c, "E"c, "F"c} Public Shared Function ToHexString(bytes() As Byte) As String Dim hexStr As String = "" Dim i As Integer For i = 0 To bytes.Length - 1 hexStr = hexStr + Hex(bytes(i)) Next i Return hexStr End Function 'ToHexString Shared Sub Main() Dim b As Byte() = {&H0, &H12, &H34, &H56, &HAA, &H55, &HFF} Console.WriteLine(ToHexString(b)) End Sub 'Main End Class 'HexTest
class HexTest { static char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; public static string ToHexString(byte[] bytes) { char[] chars = new char[bytes.Length * 2]; for (int i = 0; i < bytes.Length; i++) { int b = bytes[i]; chars[i * 2] = hexDigits[b >> 4]; chars[i * 2 + 1] = hexDigits[b & 0xF]; } return new string(chars); } static void Main() { byte[] b = {0x00, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF}; Console.WriteLine(ToHexString(b)); } }
ref class HexTest { private: static array<Char>^hexDigits = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; public: static String^ ToHexString( array<Byte>^bytes ) { array<Char>^chars = gcnew array<Char>(bytes->Length * 2); for ( int i = 0; i < bytes->Length; i++ ) { int b = bytes[ i ]; chars[ i * 2 ] = hexDigits[ b >> 4 ]; chars[ i * 2 + 1 ] = hexDigits[ b & 0xF ]; } return gcnew String( chars ); } }; int main() { array<Byte>^b = {0x00,0x12,0x34,0x56,0xAA,0x55,0xFF}; Console::WriteLine( HexTest::ToHexString( b ) ); }
class HexTest { private static char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; public static String ToHexString(ubyte bytes[]) { char chars[] = new char[bytes.get_Length() * 2]; for (int i = 0; i < bytes.get_Length(); i++) { int b = System.Convert.ToInt32( System.Convert.ToString(bytes.get_Item(i))); chars.set_Item((i * 2), hexDigits.get_Item(b >> 4)); chars.set_Item((i * 2 + 1), hexDigits.get_Item(b & 0xF)); } return new String(chars); } //ToHexString public static void main(String[] args) { ubyte b[] = { 0x0, 0x12, 0x34, 0x56, 0xAA, 0x55, 0xFF }; Console.WriteLine(ToHexString(b)); } //main } //HexTest
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ