Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Convert string to int
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { var strNumber = "123456789"; //Your code goes here var result = ConvertStringToInt(strNumber, 10); Console.WriteLine(result); } public static int ConvertStringToInt(string str, int baseNumber){ var len = str.Length; var result = 0; for(var i = 0; i < len; i++){ result += ConvertCharToInt(str[i]) * (int)Math.Pow(baseNumber, len - i - 1); } return result; } public static int ConvertCharToInt(char ch){ return (int)ch - 0x30; } } }
run
|
edit
|
history
|
help
0
ch.murali krishna
Problem_binary
Delegates
Tree Node Sample
HawkSearch field naming convention
1
c# integers
compiled prog
puzzle piezas
SHA tester