+ 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
2 Antworten
+ 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
Solo Wanderer 4315
Solo Wanderer 4315 - avatar