Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD

Part 5 - Program to check if the user input is a string or an integer

Suggested Videos:
Part 2 - Display database table metadata in asp.net web application
Part 3 - How to bind a computed column to GridView
Part 4 - Subtract the largest even number and smallest odd number in the given array elements



This is straight forward in C#. If you have used TryParse() function then you already know the answer.



using System;
namespace Demo
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Please type your input and press Enter key");
            string strInput = Console.ReadLine();

            int result = 0;
            if (int.TryParse(strInput, out result))
            {
                Console.WriteLine("Your input {0} is a number", result);
            }
            else
            {
                Console.WriteLine("Your input {0} is NOT a number", strInput);
            }
        }
    }

}

dot net written test questions answers

No comments:

Post a Comment

If you like this website, please share with your friends on facebook and Google+ and recommend us on google using the g+1 button on the top right hand corner.