It is unclear why it says: "No overload for the method takes 0 arguments"

I have to take user input and retype it into alternate capital letters. I took a string and converted it to a char array, and I'm trying to do this using the rest of the position in the array.

The problematic lines are the y = letter.ToUpper () and y = letter.ToLower () lines, which give me the error "No overload for the" ToUpper "/" ToLower "method takes 0 arguments. I'm not sure why I get an error even after looking examples of other people.

static void Main(string[] args)
    {
        Console.Write("Enter anything: ");
        String x = Console.ReadLine();
        char[] array = x.ToCharArray();

        for(int i = 0; i<array.Length; i++)
        {
            char letter = array[i];
            char y;
            if(i % 2 == 0)
            {
                y = letter.ToUpper();
                Console.Write(y);
            }
            else if(i % 2 == 1)
            {
                y = letter.ToLower();
                Console.Write(y);
            }                
        }
    }
+4
source share
2 answers

In contrast string, it chardoes not have instance methods ToUpper()or ToLower().

, .

char.ToLower(y).

+4

char.ToLower - , , CultureInfo.

, , , :

y = char.ToUpper(letter);

y = char.ToLower(letter);

, , :

for(int i = 0; i < array.Length; i++)
{
    char letter = array[i];
    char y = i % 2 == 0 ? char.ToUpper(letter) : char.ToLower(letter);
    Console.Write(y);
}
+4

All Articles