I have what I think is an easy problem. For some reason the following code generates the exception, \"String must be exactly one character long\".
int n = 0;
for
Convert.ToChar( string s )
, per the documentation requires a single character string, otherwise it throws a FormatException
as you've noted. It is a rough, though more restrictive, equivalent of
public char string2char( string s ) { return s[0] ; }
Your code does the following:
char
is an integral type: its an unsigned 16-bit integral value.What exactly are you trying to accomplish here. For instance, given a charMsg
that consist of 3 characters, 'a', 'b' and 'c', what should happen. A clear problem statement helps us to help you.