This snippet accepts a string which is assumed to be the string version of one of the members and returns an enum object with the respective member selected.*
*Thanks to user: mcbutterbuns for improving upon my version of this snippet
- public enum PayTypeList
- PayTypeList payType = (PayTypeList)Enum.Parse(typeof(PayTypeList), "Hourly");
- // Throws an ArgumentException if the string is found not to be one of the members of the enum (in this case, if you pass in a string "Weekly" instead of "Hourly", it will throw an ArgumentException)
CommentsSubscribe to comments
You need to login to post a comment.