Interviews4 answers
How can you read an integer value from the keyword when the application is runtime?example?
4 Answers
using Console.Readline()
Rahul PrajapatPosted Jun 1, 2015, 6:02 PM EDT
using Console.Readline()
Pankaj Kumar ChoudharyPosted Jun 1, 2015, 8:49 AM EDT
We can also use int.Parse to conver string into integar.
Example:
String abc="500";
int num=int.Parse(abc);
Console.writeline(num);
It will also give output 500
Piyush chhabraPosted Apr 20, 2015, 3:23 AM EDT
You can use the console.ReadLine()method to read a value an integer from the keyboard, but console.ReadLine() method returns String value.Therefore, if you want to read an integer value , you need to convert the value returned by console.ReadLine() into an integer value.
Syntax:
int value=convert.ToInt32(console.ReadLine());
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
public void f1()
{
int score;
System.Console.WriteLine("Enter the Score");
score = Convert.ToInt32(Console.ReadLine()); // convert here intger value
switch (score)
{
case 100:
Console.WriteLine("Century");
break;
case 200:
Console.WriteLine("Double Century");
break;
default:
Console.WriteLine("Invalid case");
}
}
static void Main(string[] args)
{
Program pro = new Program();
pro.f1();
Console.ReadLine();
}
}
}
Krishna Rajput SinghPosted Jul 16, 2014, 3:35 AM EDT



