using System;
using System.Collections.Generic;
using System.Text;
namespace ProgrammerDictionaryTutorialCode
{
class IfStatementUsingConsoleReadLineAndBool
{
//Entry point for the program
public static void Main()
{
//Opening statement of program
Console.WriteLine("Please Enter a word or a number");
//allows enduser to type into the console application and be read by program
string userInput = Console.ReadLine();
// in this foreach statement, variable s is tied to the line that is read from the userInput
foreach (var s in userInput)
{
//declared the word number refers to an integer
int number;
//boolean result (true or false) for the typed word or letter from end user.
//TryParse Converts the string representation of a number to its 32-bit signed integer equivalent.
bool result = Int32.TryParse(s.ToString(), out number);
if (result)// is true for being a number or integer
{
Console.WriteLine("I am a number", number);
}
else// result is false and is a word or letter
{
Console.WriteLine("I am a string");
}
//makes it so we can again read the response.
Console.Read();
}
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ProgrammerDictionaryTutorialCode
{
class IfStatementUsingConsoleReadLineAndBool
{
//Entry point for the program
public static void Main()
{
//Opening statement of program
Console.WriteLine("Please Enter a word or a number");
//allows enduser to type into the console application and be read by program
string userInput = Console.ReadLine();
// in this foreach statement, variable s is tied to the line that is read from the userInput
foreach (var s in userInput)
{
//declared the word number refers to an integer
int number;
//boolean result (true or false) for the typed word or letter from end user.
//TryParse Converts the string representation of a number to its 32-bit signed integer equivalent.
bool result = Int32.TryParse(s.ToString(), out number);
if (result)// is true for being a number or integer
{
Console.WriteLine("I am a number", number);
}
else// result is false and is a word or letter
{
Console.WriteLine("I am a string");
}
//makes it so we can again read the response.
Console.Read();
}
}
}
}