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
Maha
NA
0
326k
Command Line Argument & int.TryParse()
Apr 29 2014 6:55 AM
This following program will check whether value is provided or not in the Command Line Argument, if value is provided whether it is a numeric or not, if it is a numeric whether it is an odd or even.
I have a problem in how
trueORfalse = int.TryParse(args[0], out n)
behave.
We know inside the
if
condition if the expression is
true
that statement becomes o/p.
But in the program if a Command Line Argument is non-numeric though trueORfalse expression is
false
(Step Into (F11-key) will show the result) statement becomes o/p. How can this situation be explained? Problem is highlighted.
using System;
class Program
{
static void Main(string[] args)
{
int n ;
bool trueORfalse = false;
if(args.Length==0)
Console.WriteLine("Command Line Argument is not provided");
else
if (trueORfalse == int.TryParse(args[0], out n))
Console.WriteLine("Provid a numeric value");
else
if(n%2==0)
Console.WriteLine("Even");
else
Console.WriteLine("Odd");
Console.Read();
}
}
Reply
Answers (
7
)
How to connect to online MySQL database
how to save dummy bill in c#