Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 29th, 2011, 04:53 AM
Registered User
 
Join Date: Apr 2011
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default using -1 for variable value p(557)

I'm wondering why you used -1 one when initiating a value for _id, why not use Zero as it also indicates that no id is available...

thanks
 
Old April 30th, 2011, 05:07 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Both would work, and both would be considered "magic numbers".... ;-)

The reason I chose -1 is that 0 is the default value for an integer that hasn't been initialized explicitly. By setting it to -1, I know I set it to -1 or undefined, and not the .NET run-time.

A better alternative would be to use a nullable int; then you can check HasValue to determine if the variable has been assigned a value not.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 30th, 2011, 06:16 AM
Registered User
 
Join Date: Apr 2011
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default

thanks for the clear explanation :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
LinkedList<T>, AddTail, EX9_22, pages 557-559 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 1 January 26th, 2010 07:03 PM
comapring global variable value to local variable amhicraig XSLT 6 December 5th, 2007 12:16 PM
Problems with Chap. 17 pg.557 & 558 alk BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 August 19th, 2007 09:58 AM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
Object variable or with block variable not set netfresher VS.NET 2002/2003 0 July 10th, 2006 02:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.