How to convert String into Int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to convert String into Int

static void Main(string[] args) { int a; Console.WriteLine("Enter a number"); a=Console.ReadLine(); if(a==100) { Console.WriteLine("Perfect"); if(a>=50) { Console.WriteLine("Passed"); } } else { Console.WriteLine("Failed"); }

21st May 2018, 6:28 AM
rahul dubey
rahul dubey - avatar
1 Answer
+ 3
You cannot directly assign string to int. You need to convert it using the methods in the Convert class. Thus, line 5 becomes : a=Convert.ToInt32(Console.ReadLine()); Secondly, please tag your threads appropriately.
21st May 2018, 6:44 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar