Case sensitiveness (For Console Application)
My current code:
string math;
<insert stuff>
math = Console.ReadLine();
if (math == "add")
{
<Insert stuff>
}
My problem is that it only triggers if you type add, not when you type ADD or whatever, any idea how I would go about this? I know it has something to do with ToLower, but I don't know what to do with it. I tried to do math.ToLower(Console.Readline()); and vice versa which of course didn't work :(.
ToLower does not modify the string argument but it returns a new string (and all other string functions behave like this, strings are imutable) so it should be:
math = Console.ReadLine();
math = math.ToLower();
if (math == "add") ...
A more efficient way to do this is to use:
// Instead of this: if ((math.ToLower()) == "add")
// Use this:if (string.Compare(
math., "add", true) == 0)
>> A more efficient way to do this is to use:
More efficient if you're doing just the one comparison. However, there's a good chance he'll want to do several, in whcih case the best solution would be:
string math = Console.ReadLine();
math = math.ToLower();
if (math == "add")
///
else if (math == "sub")
///
else if (math == "times")