C# 不用系统自带的方法将字符串类型123456转换为值类型
static void Main(string[] args) { string numString = "123045"; long num = GetNum(numString); Console.WriteLine(num); } private static long[] ten = new long[] { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000 }; public static long GetNum(string NumString) { char[] NumArray = NumString.ToCharArray(); long Num = 0L; for (int i = NumArray.Length - 1, j = 0; i >= 0; i--, j++) { Num += (NumArray[i] - ‘0‘) * ten[j]; } return Num; }
原文地址:https://www.cnblogs.com/heyangyi/p/8809870.html
时间: 2024-10-15 01:51:51