TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Enum.TryParse Unexpected Behavior

1 pointsby freedudealmost 2 years ago

3 comments

colejohnson66almost 2 years ago
I would argue that using `Enum.TryParse` on integers means you're doing something wrong. If I have an integer, even if it's as a string, I can just cast it to the enum type (after parsing the string if needed), hence why `Enum.IsDefined` exists.
freedudealmost 2 years ago
&quot;Enum.TryParse does the following:<p><pre><code> Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object. The return value indicates whether the conversion succeeded. &quot;</code></pre>
freedudealmost 2 years ago
Reference:<p>A better enumeration - Type safe from start to end<p><a href="https:&#x2F;&#x2F;steven-giesel.com&#x2F;blogPost&#x2F;74c47c63-ebf0-44d9-85af-d4e4803a63b4" rel="nofollow noreferrer">https:&#x2F;&#x2F;steven-giesel.com&#x2F;blogPost&#x2F;74c47c63-ebf0-44d9-85af-d...</a>