473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help - Creating a function to deal with null parameters

Hi guys,

Say for example i have a hypothetical function taking 4 parameters such as the one below:

public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
}

If i have a piece of data missing such as height, but i still want to call the function that will add the other parameters into the database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without getting compiler errors?

Thanks in advance

Paul
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Feb 13 '07 #1
2 1254
In .NET 2.0, you can use

public void InsertRow(char? gender, double? decimalAge, double? height,
double? weight)
{
if( gender == null )
{
//not provider
}
else
{
field = (char) gender;
}
....

--

"Paul C. Jarvis" <pj*****@man.ac.ukwrote in message
news:Za*********************@giganews.com...
Hi guys,

Say for example i have a hypothetical function taking 4 parameters such as
the one below:

public void InsertRow(char gender, double decimalAge, double height,
double weight)
{
//Adds data into a MySQL database
}

If i have a piece of data missing such as height, but i still want to call
the function that will add the other parameters into the database, how
would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without
getting compiler errors?

Thanks in advance

Paul
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.8 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Feb 13 '07 #2
<Paul C. Jarvis (pj*****@man.ac.uk)wrote:
Say for example i have a hypothetical function taking 4 parameters
such as the one below:

public void InsertRow(char gender, double decimalAge, double height, double weight)
{
//Adds data into a MySQL database
}

If i have a piece of data missing such as height, but i still want to
call the function that will add the other parameters into the
database, how would i do it? I'd like to pass
a 'null' to the function, is there any way of achieving this without
getting compiler errors?
Well, char and double values can't be null. You options are:
1) On .NET 2.0, use nullable types: char? and double?
See http://pobox.com/~skeet/csharp/csharp2/nullable.html for more on
this

2) Otherwise, have particular char and double values that you wouldn't
normally actually use, and have those be "special" ways of representing
null. It's a bit hacky, admittedly...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: gaulle | last post by:
i'm a newbie in c. now i 'm learning it.i read a code,and compile it in dev-c++4.9.9.0.it can be compiled and pass.but there are some warnings.while in TC2.0,no any warning.it's why? #include...
23
by: bluejack | last post by:
Ahoy... before I go off scouring particular platforms for specialized answers, I thought I would see if there is a portable C answer to this question: I want a function pointer that, when...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
1
by: Nestor | last post by:
Hello all, I'm begining in the web services world and I've reading about how to invoke them using javascript from Mozilla browser (version 2.0 in my case). I found a very interesting example...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.