TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
harish reddy
NA
162
33.4k
Console readline query
Jun 3 2017 9:17 AM
Console.WriteLine("Program to calculate weight of man on moon by given weight on earth");
Console.WriteLine("Enter mass on earth");
Console.ReadLine();
int m1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter gravity on earth");
int g1 = int.Parse(Console.ReadLine());
int weightonearth = m1 * g1;
Console.WriteLine("Weight on earth is " + " " + weightonearth);
Console.ReadLine();
Console.WriteLine("Now lets calculate weight on moon based on weight on earth");
double weightonmoon = 0.17 * weightonearth;
Console.WriteLine("Weight on moon is " + " " + weightonmoon);
The above program is throwing exception error . Why?
but, if i give like below its not throwing error.
Console.WriteLine("Program to calculate weight of man on moon by given weight on earth");
Console.WriteLine("Enter mass on earth");
string a= Console.ReadLine();
int m1 = int.Parse(a);
Console.WriteLine("Enter gravity on earth");
int g1 = int.Parse(Console.ReadLine());
int weightonearth = m1 * g1;
Console.WriteLine("Weight on earth is " + " " + weightonearth);
Console.ReadLine();
Console.WriteLine("Now lets calculate weight on moon based on weight on earth");
double weightonmoon = 0.17 * weightonearth;
Console.WriteLine("Weight on moon is " + " " + weightonmoon);
In this way if it is correct then int g1 = int.Parse(Console.ReadLine()); should also throw me exception error right? But its not throwing error.
One more question is : does console.readline always assume the datatype as string?
Reply
Answers (
1
)
How To Use Group Join In C# Linq.
C# datagridview and specific column report in iTextsharp