Click here to Skip to main content
15,887,175 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Converting a string to an int Pin
PIEBALDconsult13-Dec-11 15:48
mvePIEBALDconsult13-Dec-11 15:48 
GeneralRe: Converting a string to an int Pin
Shameel13-Dec-11 17:53
professionalShameel13-Dec-11 17:53 
GeneralRe: Converting a string to an int Pin
PIEBALDconsult14-Dec-11 1:49
mvePIEBALDconsult14-Dec-11 1:49 
GeneralRe: Converting a string to an int Pin
Rob Grainger15-Dec-11 22:34
Rob Grainger15-Dec-11 22:34 
GeneralRe: Converting a string to an int Pin
_Damian S_13-Dec-11 15:50
professional_Damian S_13-Dec-11 15:50 
GeneralRe: Converting a string to an int Pin
Shameel13-Dec-11 17:54
professionalShameel13-Dec-11 17:54 
GeneralRe: Converting a string to an int Pin
_Damian S_13-Dec-11 19:42
professional_Damian S_13-Dec-11 19:42 
GeneralRe: Converting a string to an int PinPopular
BobJanova13-Dec-11 23:29
BobJanova13-Dec-11 23:29 
This isn't bad, just outdated. Before the introduction of TryParse this is basically how you had to do it (though I would use int.Parse not Convert.ToInt32, but one calls the other I think). Although you could argue it should be in a single utility method, it's only a couple of lines so it's hardly worth it.

A try block uses almost no resources, and the exception will only be thrown when the requested string isn't a valid number, so I doubt there's any noticeable performance impact from doing this.

Annoying to deal with when you have a better solution available to you now, and you have debugging set to look at caught exceptions? Yeah, probably. But it's not really bad code. If you're complaining that the debugger stops on it, try adjusting your settings – otherwise you can use that as an argument against any catch blocks and I'm sure you can see how that becomes an absurd position to hold pretty quickly.
GeneralRe: Converting a string to an int Pin
PIEBALDconsult14-Dec-11 1:51
mvePIEBALDconsult14-Dec-11 1:51 
GeneralRe: Converting a string to an int Pin
Shameel14-Dec-11 3:41
professionalShameel14-Dec-11 3:41 
GeneralRe: Converting a string to an int Pin
BobJanova14-Dec-11 3:50
BobJanova14-Dec-11 3:50 
RantDocumentation failure PinPopular
DerekT-P13-Dec-11 3:17
professionalDerekT-P13-Dec-11 3:17 
GeneralRe: Documentation failure Pin
GibbleCH13-Dec-11 4:29
GibbleCH13-Dec-11 4:29 
GeneralRe: Documentation failure Pin
DerekT-P13-Dec-11 4:52
professionalDerekT-P13-Dec-11 4:52 
GeneralRe: Documentation failure Pin
Nagy Vilmos13-Dec-11 5:27
professionalNagy Vilmos13-Dec-11 5:27 
GeneralRe: Documentation failure Pin
BobJanova13-Dec-11 23:42
BobJanova13-Dec-11 23:42 
GeneralRe: Documentation failure Pin
Nagy Vilmos13-Dec-11 23:54
professionalNagy Vilmos13-Dec-11 23:54 
GeneralRe: Documentation failure Pin
DerekT-P14-Dec-11 3:48
professionalDerekT-P14-Dec-11 3:48 
GeneralRe: Documentation failure Pin
Sander Rossel20-Dec-11 7:59
professionalSander Rossel20-Dec-11 7:59 
GeneralRe: Documentation failure Pin
BillW3321-Dec-11 3:05
professionalBillW3321-Dec-11 3:05 
GeneralDo you not understand booleans? PinPopular
alanevans6-Dec-11 1:11
alanevans6-Dec-11 1:11 
GeneralRe: Do you not understand booleans? PinPopular
CDP18026-Dec-11 1:49
CDP18026-Dec-11 1:49 
GeneralRe: Do you not understand booleans? PinPopular
harold aptroot6-Dec-11 2:36
harold aptroot6-Dec-11 2:36 
GeneralRe: Do you not understand booleans? Pin
Fabio Franco12-Dec-11 8:05
professionalFabio Franco12-Dec-11 8:05 
GeneralRe: Do you not understand booleans? Pin
mostlyharmless196414-Dec-11 3:15
mostlyharmless196414-Dec-11 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.