Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageFor 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).
Post Follow-up to this messageUse 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
Post Follow-up to this message> 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)
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.