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; }
博客内容仅代表个人观点,如发现阐述有误,麻烦指正,谢谢!