c# string convert char

I am new to C#, both of the values below are valid, what is the difference between them?

char tt = convert.tochar(string value);

char tt = char.parse(string value);

what is the difference between the two

Hello friends, I am new to C#, both of the values below are valid, what is the difference between them?

>Solution :

There’s no real difference.

Both Convert.ToChar(string value), and char.Parse(string s) expect a string with 1 character, and throw FormatException if this is not the case.

If the string does contain 1 character, they both return it as a char.

Note:
The answer above refers to the specific overloads that you mentioned in the question.
As you can see in the link above Convert.ToChar has other overloads (e.g. ToChar(String, IFormatProvider)), which offer options that you don’t have with char.Parse.

Leave a Reply