How to parse user input using C# (.NET)
Many times we do not get the anticipated input from the user (either as direct entry / through some input files). Converting the input, for example, to say integer can be done as shown below
public static void TryParse_Examples()
{
bool bConversion;
int result;
// Failure //
bConversion = int.TryParse(null, out result);
if (bConversion == false)
{
MessageBox.Show ("Error Occurred!");
}
// Failure //
bConversion = int.TryParse("s1", out result);
if (bConversion == false)
{
MessageBox.Show("Error Occurred!");
}
// Success //
bConversion = int.TryParse("100", out result);
if (bConversion == false)
{
MessageBox.Show("Error Occurred!");
}
}
Hi,
ReplyDeleteThank you for nice post. Please keep posting such a nice stuff. I would like to introduce another good C# blog, Have a look.
http://CSharpTalk.com
Sonam