Converting capitalized to lowercased and vise versa

Viewed 30

So the issuie is that i don't undertsand why out is not compatible with the char. Because when I created a simular program but starting of the line of code where the issuie is with an int it worked out fine. The worng code is that the out gives error. Can someone please explain whats more compatible? Thanks in advance :)

string Input = TxbG.Text.ToString();
            Convert(Input);
        }
        void Convert(string Input)
        {
            char Output; bool Try = char.IsUpper(Input, **out** Output);
            string Return = Input.ToString();
            if (Try == true)
            {
                Return.ToUpper();
            }
            else
            {
                Return.ToLower();
            }
            TxbV.Text = (Return);*emphasized text*
1 Answers

Char.IsUpper will check only a single character and by looking at your example you are trying to check an entire string. You can check each character one by one but not an entire string. Also the method Char.IsUpper has two overloads. One is a single character and the other is a string with the character index. So the out worked with int because it was able to recognize a method with int parameter. You can try the following code for checking the string

bool IsAllUpper(string input)
{
  for (int i = 0; i < input.Length; i++)
  {
    if (!Char.IsUpper(input[i]))
         return false;
  }

return true;
}
Related