ByteConverter 类

提供将 8 位无符号整数对象与其他各种表示形式互相转换的类型转换器。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public Class ByteConverter
    Inherits BaseNumberConverter
用法
Dim instance As ByteConverter
public class ByteConverter : BaseNumberConverter
public ref class ByteConverter : public BaseNumberConverter
public class ByteConverter extends BaseNumberConverter
public class ByteConverter extends BaseNumberConverter

备注

此转换器只能将 8 位无符号整数与字符串进行相互转换。

有关类型转换器的更多信息,请参见 TypeConverter 基类和 如何:实现类型转换器

提示

无论何时都不要创建 ByteConverter 的实例。而应调用 TypeDescriptorGetConverter 方法。有关更多信息,请参见 TypeConverter 基类中的示例。

应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedStateHostProtectionAttribute 不影响桌面应用程序(这些应用程序通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例声明并初始化一个 8 位无符号整数和一个字符串。然后,这些代码分别在这二者之间进行相互转换。

Dim myUint As Byte = 5 
Dim myUStr As String = "2"
Console.WriteLine(TypeDescriptor.GetConverter(myUint).ConvertTo(myUint, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(myUint).ConvertFrom(myUStr))
byte myUint = 5;
string myUStr = "2";
Console.WriteLine(TypeDescriptor.GetConverter(myUint).ConvertTo(myUint, typeof(string))); 
Console.WriteLine(TypeDescriptor.GetConverter(myUint).ConvertFrom(myUStr));    
Byte myUint(5);
String^ myUStr = "2";
Console::WriteLine( TypeDescriptor::GetConverter( myUint )->ConvertTo( myUint, String::typeid ) );
Console::WriteLine( TypeDescriptor::GetConverter( myUint )->ConvertFrom( myUStr ) );
ubyte myUint = 5;
String myUStr = "2";
Console.WriteLine(TypeDescriptor.GetConverter((System.Byte)(myUint)).
    ConvertTo((System.Byte)(myUint), String.class.ToType()));
Console.WriteLine(TypeDescriptor.GetConverter((System.Byte)myUint).
    ConvertFrom(myUStr));

继承层次结构

System.Object
   System.ComponentModel.TypeConverter
     System.ComponentModel.BaseNumberConverter
      System.ComponentModel.ByteConverter

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

ByteConverter 成员
System.ComponentModel 命名空间