Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert string to char?
Message
From
05/06/2008 12:36:13
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01321885
Message ID:
01321899
Views:
12
This message has been marked as a message which has helped to the initial question of the thread.
Hi Naomi,

If it's for sure that letterCode will have one and only one character, then no problem. But, if for some reason it had more characters it could messy. One way to mitigate this would be to use the string ToCharArray() method ( letterCode.ToCharArray() ), then load the first character of the array into the char variable, or simply load the first character of the string which should be a char ( letterCode[0] ).

Bill

>Hi everybody,
>
>This is very simple quick question. I created a char property called PersonType. I also have a string letterCode (it declared a string, but it is actually one letter character).
>
>How can I do
>this.PersonType = letterCode ;
>
>I tried this.PersonType = (char) letterCode; but this didn't work.
>
>Thanks in advance.
>
>UPDATE. Took a minute break and the answer came to me.
>
>this.PersonType = Convert.ToChar(letterCode);
William A. Caton III
Software Engineer
MAXIMUS
Atlanta, Ga.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform