CharConverter
Class
Definition
Provides a type converter to convert Unicode character objects to and from various other representations.
public class CharConverter : System.ComponentModel.TypeConverter
- Inheritance
Inherited Members
System.ComponentModel.TypeConverter
System.Object
Examples
The following code example converts a variable of type Char to a string variable, and vice versa.
char chrA('a');
String^ strB = "b";
Console::WriteLine( TypeDescriptor::GetConverter( chrA )->ConvertTo( chrA, String::typeid ) );
Console::WriteLine( TypeDescriptor::GetConverter( chrA )->ConvertFrom( strB ) );
Char chrA='a';
string strB="b";
Console.WriteLine(TypeDescriptor.GetConverter(chrA).ConvertTo(chrA, typeof(string)));
Console.WriteLine(TypeDescriptor.GetConverter(chrA).ConvertFrom(strB));
Dim chrA As [Char] = "a"c
Dim strB As String = "b"
Console.WriteLine(TypeDescriptor.GetConverter(chrA).ConvertTo(chrA, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(chrA).ConvertFrom(strB))
Remarks
This converter can only convert a string, with a length of 1, to and from a character.
For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.
Note
You should never create an instance of a CharConverter. Instead, call the GetConverter method of the TypeDescriptor class. For more information, see the examples in the TypeConverter base class.
Constructors
| CharConverter() |
Initializes a new instance of the CharConverter class. |
Methods
| CanConvertFrom(ITypeDescriptorContext, Type) |
Gets a value indicating whether this converter can convert an object in the given source type to a Unicode character object using the specified context. |
| ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) |
Converts the given object to a Unicode character object. |
| ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type) |
Converts the given value object to a Unicode character object using the arguments. |