Export (0) Print
Expand All

Int32Converter Class

Provides a type converter to convert 32-bit signed integer objects to and from other representations.

For a list of all members of this type, see Int32Converter Members.

System.Object
   System.ComponentModel.TypeConverter
      System.ComponentModel.BaseNumberConverter
         System.ComponentModel.Int32Converter
            System.Windows.Forms.ImageIndexConverter

[Visual Basic]
Public Class Int32Converter
   Inherits BaseNumberConverter
[C#]
public class Int32Converter : BaseNumberConverter
[C++]
public __gc class Int32Converter : public BaseNumberConverter
[JScript]
public class Int32Converter extends BaseNumberConverter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

This converter can only convert a 32-bit signed integer object to and from a string. The Int32 value type represents signed integers with values ranging from negative 2,147,483,648 through positive 2,147,483,647.

The ConvertFrom method uses the Parse method of Int32 with the integer value of NumberStyles.

The ConvertTo method uses the general ("G") format for the string returned.

For more information about type converters, see the TypeConverter base class and Implementing a Type Converter.

Note   You should never create an instance of an Int32Converter. Instead, call the GetConverter method of TypeDescriptor. For more information, see the examples in the TypeConverter base class.

Example

[Visual Basic, C#, C++] The following sample converts a variable of type Int32 to a string and vice versa.

[Visual Basic] 
Dim myInt32 As Integer = -967299
Dim myInt32String As String = "+1345556"
Console.WriteLine(TypeDescriptor.GetConverter(myInt32).ConvertTo(myInt32, GetType(String)))
Console.WriteLine(TypeDescriptor.GetConverter(myInt32).ConvertFrom(myInt32String))

[C#] 
int myInt32 = -967299;
string myInt32String = "+1345556";
Console.WriteLine(TypeDescriptor.GetConverter(myInt32).ConvertTo(myInt32, typeof(string))); 
Console.WriteLine(TypeDescriptor.GetConverter(myInt32).ConvertFrom(myInt32String));    

[C++] 
int myInt32( -967299 );
String* myInt32String = S"+1345556";
Console::WriteLine(TypeDescriptor::GetConverter(__box(myInt32))->ConvertTo(__box(myInt32), __typeof(String)));
Console::WriteLine(TypeDescriptor::GetConverter(__box(myInt32))->ConvertFrom(myInt32String));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

Int32Converter Members | System.ComponentModel Namespace

Show:
© 2014 Microsoft