Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading