Training
Module
Convert Data Types Using Casting and Conversion Techniques in C# - Training
Explore using C# techniques for casts and conversions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This example converts a hexadecimal string to an integer using the Convert.ToInt32 method.
Use the ToInt32(String, Int32) method to convert the number expressed in base-16 to an integer.
The first argument of the ToInt32(String, Int32) method is the string to convert. The second argument describes what base the number is expressed in; hexadecimal is base 16.
' Assign the value 49153 to i.
Dim i As Integer = Convert.ToInt32("c001", 16)
Note that the hexadecimal string has the following restrictions:
&h
prefix._
digit separator.If the prefix or a digit separator is present, the call to the ToInt32(String, Int32) method throws a FormatException.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Training
Module
Convert Data Types Using Casting and Conversion Techniques in C# - Training
Explore using C# techniques for casts and conversions.