-
Hi Adnan,
Well, I don't think you will have values that are 0 or less than 0. So, Ben's solution will work smoothly for 99.9% scenario's.
by azamsharp on 5/3/2008 12:17:52 PM
-
-
I'm assuming that that is an identity key, but you could easily change that to some other "magic" value.
by subdigital on 5/3/2008 12:19:46 PM
-
-
yes benn's solution is best IF value woule be more than 0. thats why i called it great :)
good job man.
thanks
by MuhammadAdnan on 5/3/2008 1:44:26 PM
-
-
Hi KeesDijk,
Nice approach! Although I would still be inclined towards Ben's solution.
by azamsharp on 5/4/2008 10:25:14 AM
-
-
Hi azamsharp, Thanks. Just wondering why you would be inclined towards Ben's solution ? I Think :
- using TryParse is more readable
- having less exit points in a function is better, at the top exiting when an argument is invalid is fine by me, but if you can avoid it easily please do
- Ben's solution doesn't work for negative id's
by KeesDijk on 5/4/2008 10:48:21 AM
-
-
One more thing! if the ID is not an integer or not in correct format then what is the best way to deal with it. In the above code I am doing nothing so it will simply return. Would it be preferred to throw an exception and let the user know what is going on. Should the user even be bothered with this thing.
by azamsharp on 5/4/2008 7:43:41 PM
-
-
Referring to your query Azam if id is not in the correct format then tryparse method will return false. No need to handle or throw any exception. TryParse is preferred because of its this very utility. It never throws an exception.
by Ahsan on 10/24/2008 12:31:51 AM
-
Please log in to refactor the code!
Login