Steven Giesel 8/17/2023

Enum.TryParse unexpected behavior

Read Original

This technical article details a subtle pitfall in C#'s Enum.TryParse method, which can return true for integer values not defined in the enum. It demonstrates the issue with code examples and recommends using Enum.IsDefined to properly validate parsed values, referencing alternative patterns like enumeration classes.

Enum.TryParse unexpected behavior

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week