# C# Program to Convert the Octal String to an Integer Number

Last Updated : 22 Jun, 2020

Given an octal number as input, we need to write a program to convert the given octal number into equivalent integer. To convert an octal string to an integer, we have to use Convert.ToInt32() function to convert the values.

Examples:

```Input : 202
Output : 130

Input : 660
Output : 432
```

Convert the item to an integer using base value 8 by using a foreach loop .

Program 1:

 `// C# program to convert an array  ` `// of octal strings to integers ` `using` `System; ` `using` `System.Text; ` ` `  `class` `Prog { ` ` `  `    ``static` `void` `Main(``string``[] args) ` `    ``{ ` `        ``string``[] str = { ``"121"``, ``"202"``, ``"003"` `}; ` `        ``int` `num1 = 0; ` `        ``try` `{ ` ` `  `            ``// using foreach loop to access each items ` `            ``// and converting to integer numbers ` `            ``foreach``(``string` `item ``in` `str) ` `            ``{ ` `                ``num1 = Convert.ToInt32(item, 8); ` `                ``Console.WriteLine(num1); ` `            ``} ` `        ``} ` `        ``catch` `(Exception ex) { ` `            ``Console.WriteLine(ex.ToString()); ` `        ``} ` `    ``} ` `} `

Output:

```81
130
3
```

Program 2:

 `// C# program to convert an array  ` `// of octal strings to integers ` `using` `System; ` `using` `System.Text; ` ` `  `namespace` `geeks { ` ` `  `class` `Prog { ` ` `  `    ``static` `void` `Main(``string``[] args) ` `    ``{ ` `        ``string``[] str = { ``"111"``, ``"543"``, ``"333"``, ``"607"``, ``"700"` `}; ` `        ``int` `num2 = 0; ` `        ``try` `{ ` ` `  `            ``// using foreach loop to access each items ` `            ``// and converting to integer numbers ` `            ``foreach``(``string` `item ``in` `str) ` `            ``{ ` `                ``num2 = Convert.ToInt32(item, 8); ` `                ``Console.WriteLine(num2); ` `            ``} ` `        ``} ` `        ``catch` `(Exception ex) { ` `            ``Console.WriteLine(ex.ToString()); ` `        ``} ` `    ``} ` `} ` `} `

Output:

```73
355
219
391
448
```

Next