
Lily P.
asked 10/30/20Method code won't work for capitalization
Hi! I am doing a code for method that will capitalize every other word in an input, however my code below does not work and I can not find the reason. Can someone pls help?
static string ToMixed (string input)
{
string output = "";
for (int i = 0; i < input.Length; i++)
{
if(i %2 == 0)
{
output = output + input[i].ToLower();
}
else
{
output = output + input[i].ToUpper();
}
}
return output;
}
static void Main(string[] args)
{
Console.Write("Write a word: ");
string input = Console.ReadLine();
string result = ToMixed(input);
Console.WriteLine(result);
Console.ReadKey();
}
The only clue ive got is in error message: No overload for method 'ToUpper (and 'ToLower') takes 0 arguments. I dont know what they mean
1 Expert Answer
That error message means that there is no version of toUpper and toLower that takes 0 arguments so you are essentially calling a method that doesn't exist.
The toLower() and toUpper() methods you are trying to use are string methods.
Although input is a string, input[i] is a character.
The equivalent methods for Char have 1 parameter and are called as follows:
Char.toLower(input[i])
Char.toUpper(input[i])
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Elise B.
10/30/20