Solved

Passing a Double parameter that has no value

Posted on 2006-06-14
4
234 Views
Last Modified: 2012-05-05
I have a line of code that looks like so:

empGradeSale = empGradeSalHome.create(ref tempAux8, ref tempAux9, grdDto.EmpPySchdCd, ref tempAux10, ref null, ref null, ref null, ref null, ref null, ref null, grdDto.LastUpdatedBy);

My problem is the "ref null".  The method they are being passed to requires them to be doubles or longs.  In C# you can't convert nulls to doubles or longs.  What do you do when you want to pass a variable that is a double or long but it has no value?
0
Comment
Question by:adonavon
4 Comments
 
LVL 6

Expert Comment

by:PoeticAudio
ID: 16904043
I use double.MinValue and then have logic in the method (in your case empGradeSalHome.create) which tests against double.MinValue, if it is MinValue then it performs the logic needed as if it were null.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16904477
Is it a method that you have control over or is it third-party ? If you control it then the OO method would be to create an overload that doesn't require the unwanted parameters to be passed.
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 16904511
Are you using C# .NET 2? If so, you can have nullable value types in...

        public double? add(double? a, double? b)
        {
            return a + b;
        }
...
        double? sum = add(null, null);
0
 

Author Comment

by:adonavon
ID: 16904718
I was hoping there was a simpler way but if not then I have to take this approach.  If no one comes up with a simpler way by end of the day then the points are yours.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now