Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: Removing leading zeros from negative string Pin
Ravi Bhavnani12-Apr-10 19:14
professionalRavi Bhavnani12-Apr-10 19:14 
AnswerRe: Removing leading zeros from negative string Pin
Luc Pattyn12-Apr-10 10:09
sitebuilderLuc Pattyn12-Apr-10 10:09 
JokeRe: Removing leading zeros from negative string Pin
PIEBALDconsult12-Apr-10 12:53
mvePIEBALDconsult12-Apr-10 12:53 
AnswerRe: Removing leading zeros from negative string Pin
jaypatel51212-Apr-10 14:17
jaypatel51212-Apr-10 14:17 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult12-Apr-10 15:12
mvePIEBALDconsult12-Apr-10 15:12 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 11:07
Paw Jershauge13-Apr-10 11:07 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 11:08
mvePIEBALDconsult13-Apr-10 11:08 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 12:20
Paw Jershauge13-Apr-10 12:20 
PIEBALDconsult wrote:
Only when it's available.
thats what i said Wink | ;) (if the method is there...)

Now why would you even consider raising/throwing an exception, thats just bad pratice. never use exception for you code-flow.
An exception should only be thrown, when it truly is an exception, like if your transfer data over the net and the cord gets unplugged, thats an exception.
Parsing data that is not correct, is not an exception.
Lets say in this case, you want to parse -002 to -2, and the value begin parsed, turns out to be "-002$" then its not an exception, then the value ("you should know"), you want to parse is incorrect, handle it. thats to correct way, I believe.

Furthermore, I believe the code engine will spin down for every exception it has to handle.

Just a short comparison:
for 1000 parsings
Parse: 4078 milliseconds

Try Parse: 0 milliseconds


I used this code to test:
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000; i++)
{
    try { int demo = int.Parse("x"); }
    catch (Exception) {}
}
sw.Stop();
Debug.WriteLine("Parse: " + sw.ElapsedMilliseconds);
sw.Reset();
sw.Start();
for (int i = 0; i < 1000; i++)
{
        int demo;
        int.TryParse("x", out demo);
}
sw.Stop();
Debug.WriteLine("Try Parse: " + sw.ElapsedMilliseconds);

With great code, comes great complexity, so keep it simple stupid...Shucks | :-\ Shucks | :-\

GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:11
mvePIEBALDconsult13-Apr-10 13:11 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 19:44
Paw Jershauge13-Apr-10 19:44 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult14-Apr-10 3:15
mvePIEBALDconsult14-Apr-10 3:15 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:15
mvePIEBALDconsult13-Apr-10 13:15 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 20:28
Paw Jershauge13-Apr-10 20:28 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult13-Apr-10 13:29
mvePIEBALDconsult13-Apr-10 13:29 
GeneralRe: Removing leading zeros from negative string Pin
Paw Jershauge13-Apr-10 20:33
Paw Jershauge13-Apr-10 20:33 
GeneralRe: Removing leading zeros from negative string Pin
PIEBALDconsult14-Apr-10 3:12
mvePIEBALDconsult14-Apr-10 3:12 
QuestionStopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 9:42
Jacob Dixon12-Apr-10 9:42 
AnswerRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 9:58
mvePIEBALDconsult12-Apr-10 9:58 
AnswerRe: Stopping threads (semi-safely).... Pin
Dave Kreskowiak12-Apr-10 9:59
mveDave Kreskowiak12-Apr-10 9:59 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:16
Jacob Dixon12-Apr-10 10:16 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 10:51
Jacob Dixon12-Apr-10 10:51 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:02
mvePIEBALDconsult12-Apr-10 13:02 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:39
Jacob Dixon12-Apr-10 13:39 
GeneralRe: Stopping threads (semi-safely).... Pin
PIEBALDconsult12-Apr-10 13:51
mvePIEBALDconsult12-Apr-10 13:51 
GeneralRe: Stopping threads (semi-safely).... Pin
Jacob Dixon12-Apr-10 13:58
Jacob Dixon12-Apr-10 13:58 

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.