Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

arg expects an int, i want to pass a null
I  have a function:

private void UpdatePersons(int PersonId, int RoleId)
{
if(RoleId == null)
//do database stuff setting RoleId column to DbNull
else
//do something else
}

So, there are situations where I would like to call this function like:
UpdatePersons(22,null)


I have hundreds of these functions, they are a DAL generated by the MS
Application Block. So I would like to find some kind of way to do this.
I fear I amy have to pass -1 instead of null and then handle it in my
dal?


Report this thread to moderator Post Follow-up to this message
Old Post
thomasamillergoogle@yahoo.com
05-14-05 09:04 PM


Re: arg expects an int, i want to pass a null
For now, yes. The best you can do is choose an "illegal" value and have
that represent null.

In v2.0 of the Framework you can declare the parameters as int?:

private void UpdatePersons(int? PersonId, int? RoleId)

and they will be able to be null. v2.0 is currently in Beta2 (available
via free download from MSDN) and is due out in production later this
year (no word as to when, but my crystal-ball prediction is at PDC
2005, in September).


Report this thread to moderator Post Follow-up to this message
Old Post
Bruce Wood
05-14-05 09:04 PM


Re: arg expects an int, i want to pass a null
Use something like "-1". A "reserved" value that should be taken up
otherwise.

null is a reserved value not applicable in valid scenarios, similary
this value. For example, a value of '-1' may mean that you want to pass
a 'null'.

--
Cheers,
Gaurav Vaish
http://mastergaurav.blogspot.com
http://mastergaurav.org


Report this thread to moderator Post Follow-up to this message
Old Post
MasterGaurav
05-14-05 09:04 PM


Re: arg expects an int, i want to pass a null
> For now, yes. The best you can do is choose an "illegal" value and have
> that represent null.
>
> In v2.0 of the Framework you can declare the parameters as int?:
>
> private void UpdatePersons(int? PersonId, int? RoleId)
>
> and they will be able to be null. v2.0 is currently in Beta2 (available
> via free download from MSDN) and is due out in production later this
> year (no word as to when, but my crystal-ball prediction is at PDC
> 2005, in September).
>

If you are not using beta2 you can use a special value to indicate a null
value or create a wrapper class for integer. I wish they would just drop the
concept of any intrinsic types being value types. The whole nullable idea is
nice, but it does not really fix problems since nullable types loose some of
the functionality you would want. Unless you are doing huge amounts of
calculations wrapper classes on all the value types will not really be
noticable to the average user. (Here is wishing that Integer, Double, Float,
etc. were wrapper classes and not value types at least)



Report this thread to moderator Post Follow-up to this message
Old Post
Lorad
05-18-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:01 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.