text: Convert a String to an Integer using Recursion | C # implementation of the approach ; Recursive function to convert string to integer ; If the number represented as a string contains only a single digit then returns its value ; Recursive call for the sub - string starting at the second character ; First digit of the number ; First digit multiplied by the appropriate power of 10 and then add the recursive result For example , xy = ( ( x * 10 ) + y ) ; Driver code
code: using System ; class GFG { static int stringToInt ( String str ) { if ( str . Length == 1 ) return ( str [ 0 ] - '0' ) ; double y = stringToInt ( str . Substring ( 1 ) ) ; double x = str [ 0 ] - '0' ; x = x * Math . Pow ( 10 , str . Length - 1 ) + y ; return ( int ) ( x ) ; } public static void Main ( String [ ] args ) { String str = "1235" ; Console . Write ( stringToInt ( str ) ) ; } }