- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Not great code, but not too damaging to have an exception unless it is invoked millions of times in a loop.
public static bool IsFrist(string theValue) { try { Convert.ToOrdinal(theValue); return true; } catch { return false; } }
Edit Admin
Too bad double.TryParse() is around for 25 years since .net BETA.
Feels to me like yet another RTFM situation, most likely from someone coming from Java since this person doesn't even know the basic value types of .net - something most C# devs learn like on the first day - and therefore used such a weird name for that useless method.
Edit Admin
What's Convert.ToOrdinal() ?
That method never existed on the Convert class of .net.
And the correct answer is as stated in the article: https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse?view=net-9.0
Admin
"...pedantry is the root of clarity"
A large portion of my career has just been vindicated! :)
Admin
Telling that simple verification functions like this should be built into .net without all the intellectual drama devs inject into their code. We've got 170IQ devs who write code like function()=>Foo.New(a => ^Bar(1).First().Flarg(a.Color) (goes on for another 256 characters) ...then Dev:"Look at this...I turn the label Blue!". Me: "Why not just turn the label blue? Wouldn't that be simple?" Dev: "Pffft...simple is relative....look at this code!!!"
Admin
I got the joke even if MaxiTB didn't.
Edit Admin
So did I, but,
ToOrdinal()
will also return true for secnod and thrid.Addendum 2025-05-12 10:18: and
FileNotFound
for brillant.Addendum 2025-05-12 10:19:
s/ToOrdinal/isFrist/
ToOrdinal()
won't throw an exception for the other cases is what I meant to say.Edit Admin
Enlighten me :-)