Convert string to integer in C#

In this article we will discuss about how to convert string to integer in C#.
  • 1011

Here we are converting string variable into integer variable. In this example two string variables are taken and they are converted into integer using Convert.ToInt32() method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string ss = "1234";
            string str = "123";
            int i = Convert.ToInt32(ss);
            int j = Convert.ToInt32(str);
            int k = i + j;
            Console.WriteLine(k);
            Console.ReadLine();
        }
    }
}

 


Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.