In .NET Framework, implement various enrolled conversions

xiaoxiao2021-03-06  54

In the .NET Framework, the SYSTEM.CONVERT class provides a comprehensive conversion function between various types and values. Two methods of these methods can easily achieve conversion between the numerical values ​​of various entries:

Convert.TOINT32 (String Value, int.com):

You can convert a string of different credits to numbers, where the FROMBASE parameter is a format, which can only be 2, 8, 10, and 16:

As the result of Convert.Toint32 ("0010", 2) is 2;

Convert.TOString (int value, int tobase):

You can convert a number to a string format of different credits, where the Tobase parameter is a format, which can only be 2, 8, 10, and 16:

As the result of Convert.TOSTRING (2, 2) is "0010"

Now we do a way to implement string free conversion: choose to turn it into a numeric type, then transfer to the corresponding enrichment string:

Public String ConvertString (String Value, Int fromBase, INT TOBASE)

{

INT INTVALUE = Convert.Toint32 (Value, fromBase);

Return Convert.TOString (INTVALUE, TOBASE);

Where frombase is the original format

Tobase is a format that will be converted into

转载请注明原文地址:https://www.9cbs.com/read-113241.html

New Post(0)