Hi,
In v1.x, the following code worked perfectly:
mobjSqlParameter.Value = strPayerBusinessName == null ? strPayerBusinessName
: (object)DBNull.Value;
However, I can't get it to work in v2. I know that the value of
strPayerBusinessName is null because if I write
strPayerBusinessName == null in the Immediate Window, it returns "true".
However, the expression does not seem to evaluate the right-hand side, no
matter what I write. E.g., the following code
mobjSqlParameter.Value = strPayerBusinessName == null ? strPayerBusinessName
: "Hello";
does not populate mobjSqlParameter.Value with the string "Hello" when
strPayerBusinessName is null.
Has this syntax been deprecated in v2?
I realise, of course, that I can write:
if(strPayerBusinessName == null)
{
mobjSqlParameter.Value = DBNull.Value;
}
else
{
mobjSqlParameter.Value = strPayerBusinessName;
}
but I'm curious as to why the ? : syntax doesn't seem to work any more.
Any assistance gratefully received.
Mark 14 1552
?: works the same as ever, but did you notice that you're using the
wrong comparison? You're returning Name when Name is null, and I
don't think that's what you intend to do! Use != instead of == or
else reverse the : branches.
-- http://www.kynosarges.de
Mark Rae <ma**@markN-O-S-P-A-M.co.uk> wrote: In v1.x, the following code worked perfectly:
mobjSqlParameter.Value = strPayerBusinessName == null ? strPayerBusinessName : (object)DBNull.Value;
However, I can't get it to work in v2. I know that the value of strPayerBusinessName is null because if I write
strPayerBusinessName == null in the Immediate Window, it returns "true".
However, the expression does not seem to evaluate the right-hand side, no matter what I write. E.g., the following code
mobjSqlParameter.Value = strPayerBusinessName == null ? strPayerBusinessName : "Hello";
does not populate mobjSqlParameter.Value with the string "Hello" when strPayerBusinessName is null.
Has this syntax been deprecated in v2?
No. I suspect something else is going on.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
You might be interested in the null coalescing operator, however, which
would let you do:
mobjSqlParameter.Value = strPayerBusinessName ?? "Hello";
See http://www.pobox.com/~skeet/csharp/c.../nullable.html for more
details.
--
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
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... You might be interested in the null coalescing operator, however, which would let you do:
mobjSqlParameter.Value = strPayerBusinessName ?? "Hello";
Perfect! Thanks a lot, Jon, as always!
See http://www.pobox.com/~skeet/csharp/c.../nullable.html for more details.
Incredibly useful!
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:uX**************@TK2MSFTNGP14.phx.gbl... "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om...
You might be interested in the null coalescing operator, however, which would let you do:
mobjSqlParameter.Value = strPayerBusinessName ?? "Hello";
Perfect! Thanks a lot, Jon, as always!
See http://www.pobox.com/~skeet/csharp/c.../nullable.html for more details.
Incredibly useful!
Yes, it's a marvel.
I do alot of web applications and while a database might find null a good
thing, we want to generate text and really hates null strings. Whatever
happens, a website sporting a brand or a trademark must never crash. And
boy, do we hate the 'Object reference not set to an instance of an object'
error..
The coalescing operator is a dream come true for us:
string someinput = Request["someinput"] ?? "";
Anyways, back to your problem, I think you shoud use () more often. This is
how I'd do it.
string s = ((a == b) ? "a" : "b");
Now I have a question for the masters of english wanting to help a swede
like me:
What da foo does 'coalescing' means and how on earth do you pronounce that
darn word?
Happy Coalescing
- Michael S
"Michael S" <no@mail.com> wrote in message
news:e8*************@TK2MSFTNGP15.phx.gbl... This is how I'd do it. string s = ((a == b) ? "a" : "b");
How would that improve things...?
What da foo does 'coalescing' means and how on earth do you pronounce that darn word?
"Coalescing", literally, means mixing together different elements / fusing
or causing to grow together. It's yet another example of a perfectly good
English word being hijacked by our friends in Seattle, cf "boxing". It's
pronounced co-a-LESS-ing
Still, nothing yet has come close to the abomination of using "leverage" as
a verb...
Michael S <no@mail.com> wrote:
<snip> Now I have a question for the masters of english wanting to help a swede like me: What da foo does 'coalescing' means and how on earth do you pronounce that darn word?
To "coalesce" things is to mix them, blend them together. It's
pronounced:
co (like the co of coke)
a (like the "er" at the end of bigger or better)
lesce (like "less" as in the opposite of "more")
--
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
On Sat, 28 Jan 2006 22:11:41 -0000, "Mark Rae"
<ma**@markN-O-S-P-A-M.co.uk> wrote: "Michael S" <no@mail.com> wrote in message news:e8*************@TK2MSFTNGP15.phx.gbl...
This is how I'd do it. string s = ((a == b) ? "a" : "b");
How would that improve things...?
What da foo does 'coalescing' means and how on earth do you pronounce that darn word?
"Coalescing", literally, means mixing together different elements / fusing or causing to grow together. It's yet another example of a perfectly good English word being hijacked by our friends in Seattle, cf "boxing". It's pronounced co-a-LESS-ing
Still, nothing yet has come close to the abomination of using "leverage" as a verb...
I'm glad you definitized how you feel about that Mark ;o)
Otis Mukinfus http://www.otismukinfus.com http://www.tomchilders.com
"Otis Mukinfus" <ph***@emailaddress.com> wrote in message
news:37********************************@4ax.com... Still, nothing yet has come close to the abomination of using "leverage" as a verb... I'm glad you definitized how you feel about that Mark ;o)
ROTFLMAO! Nice one! If anyone ever burglarizes me, I'll certainly make sure
they're hospitalized... :-)
Now then, let me just find a sentence in which I can use the phrase "off
of"...
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Michael S <no@mail.com> wrote: ... It's pronounced: co (like the co of coke) a (like the "er" at the end of bigger or better) lesce (like "less" as in the opposite of "more")
Co-ER-less? Hey, no teaching people the redneck version! :) http://www.m-w.com/cgi-bin/audio.pl?coales01.wav
Mike <vi********@yahoo.com> wrote: "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message news:MP************************@msnews.microsoft.c om... Michael S <no@mail.com> wrote: ... It's pronounced: co (like the co of coke) a (like the "er" at the end of bigger or better) lesce (like "less" as in the opposite of "more")
Co-ER-less? Hey, no teaching people the redneck version! :) http://www.m-w.com/cgi-bin/audio.pl?coales01.wav
That's got the "er" though. There's no emphasis or length on it - but
the main thing is that it's not "coal"-"less" (as in a lack of coal) :)
--
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
I wouldn't say "er" as in "better". It's actually the schwa: an
unstressed vowel sound, such as "a" in "above" or "o" in "melon", often
transcribed as "uh", so:
co-uh-LESS
Sounds like a extract from a campaign speech by Dubya ;-p
Bruce Wood wrote: I wouldn't say "er" as in "better". It's actually the schwa: an unstressed vowel sound, such as "a" in "above" or "o" in "melon", often transcribed as "uh", so:
co-uh-LESS
"uh" is good, yes. As it happens, I pronounce the "er" of better in the
same way as the "a" of above, but slightly differently to the "o" of
"melon"... (I'd be hard pressed to describe the exact difference,
admittedly.)
Jon
Well stop it now =)
While asking for a joke, I got some jokes. Now it's getting polical and
even a troll like me knows this is a no-no in this forum.
Happy Coding
- Michael S This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: neblackcat |
last post by:
Would anyone like to comment on the following idea?
I was just going to offer it as a new PEP until it was suggested that
I post it here for comment & consideration against PEP 308.
I'm far...
|
by: Ney André de Mello Zunino |
last post by:
Hello.
I have noticed, in a lot of C and C++ code, that many programmers seem
to prefer putting the test values first in conditional expressions.
I.e., they would rather write this:
if (-1 ==...
|
by: Reinhold Birkenfeld |
last post by:
Hi,
after Guido's pronouncement yesterday, in one of the next versions of Python
there will be a conditional expression with the following syntax:
X if C else Y
which is the same as today's...
|
by: Raghavendra R A V, CSS India |
last post by:
hie..
Do any one knows how to write a C program without using the
conditional statements if, for, while, do, switch, goto and even
condotional statements ? It would be a great help for me if...
|
by: Chris Dunaway |
last post by:
Consider this code (.Net 2.0) which uses a nullable type:
private void button1_Click(object sender, System.EventArgs e)
{
DateTime? nullableDate;
nullableDate = (condition) ? null :...
|
by: Olov Johansson |
last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7
and Konqueror 3.5) has support not only for standard function
definitions, function expressions (lambdas) and Function...
|
by: volcs0 |
last post by:
I've done this in Scheme, but I'm not sure I can in Python.
I want the equivalent of this:
if a == "yes":
answer = "go ahead"
else:
answer = "stop"
in this more compact form:
|
by: A.M |
last post by:
Hi,
I am using Python 2.4. I read the PEP 308 at:
http://www.python.org/dev/peps/pep-0308/
|
by: paulo |
last post by:
Can anyone please tell me how the C language interprets the following
code:
#include <stdio.h>
int main(void)
{
int a = 1;
int b = 10;
int x = 3;
|
by: Nicholas M. Makin |
last post by:
I was just thinking that I understood the conditional operator when I coded
the following expecting it to fail:
int a= 10, b= 20, c= 0;
((a < b) ? a : b) = c; // a=0
a=20; b= 10;
((a < b) ? a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
| |