string choice = String.ToUpper(Console.ReadLine());
I want to input a string and convert it to upper case. However, there's an error that states :
cannot convert from 'string' to System.Globalization.CultureInfo'
that appears when I hover over the Console.ReadLine()
. Why doesn't this work , and what fixes are there? And is there another way to do this ?
It does not works this way.
The ToUpper method belongs to String class. It takes a parameter of type System.Globalization.CultureInfo.
You can write :
string choice = Console.ReadLine().ToUpper();
String.ToUpper
is an instance method, that means you have to use it "on" your string:Otherwise you are using the overload that takes a
CultureInfo
object. SinceString
is not convertible toSystem.Globalization.CultureInfo
you get the compiler error. But it's misleading anyway, you can't use an instance method without instance, so this yields another error:A method can be used without an instance of the type only if it is
static
.Maybe you can try this:
What I do:
I get an input from the user. Let's suppose it is a lowercase word. I convert each characters in it to int (I get the ASCII code) and I put it into
int current
. For example 'a' = 97 (in ASCII code), and 'A' is 65. So 'A' is smaller than 'a' with 32 in ASCII code. For 'b' and 'c'... this algorithm also works. But beware! This only works for english letters! And then I decreasecurrent
(the ASCII value) with 32. I convert it back to a character and add it tostring output
. After thefor
loopI hope it helps. :D