How to convert string to int number in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            const string s = "834";

            int n = int.Parse(s);

            Console.WriteLine(n);
        }
    }
}


/*
run:
       
834
   
*/

 



answered May 10, 2018 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            const string s = "9812";
            int n;

            if (int.TryParse(s, out n))
                Console.WriteLine(n);
            else
                Console.WriteLine("String could not be parsed");
        }
    }
}


/*
run:
       
9812
   
*/

 



answered May 10, 2018 by avibootz

Related questions

1 answer 208 views
1 answer 286 views
1 answer 288 views
1 answer 256 views
2 answers 279 views
1 answer 372 views
...