+ 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 Antwort
+ 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