abc = Encoding.GetEncoding("xyz"); //Throws exception if xyz non existing.
Is there a way to tryget encoding or do you have to catch the exception?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
Encoding.GetEncodingsfirst, and then try to find one matching the name:If you do this regularly, you may well want to build a dictionary of name/encoding once, and then use
TryGetValueon that instead.