How to convert string to enum in Linq using C#?
Does the type casting below also work in linq?:
(Audience)Enum.Parse(typeof(Audience), value, true);
If yes, please tell me how I can use this?
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.
Given the enum
the code below performs conversion from
enumtostringand vice-versa:So, yes the casting works. However, keep in mind that the query above will throw an
ArgumentExceptionifEnum.Parsemethod receives a value that cannot be parsed.This updated version only returns values that parse sucessfully