• Welcome to Valhalla Legends Archive.
 

[C#] The ?? operator??

Started by MyndFyre, December 12, 2006, 02:29 AM

Previous topic - Next topic

MyndFyre

This one got by me!

Apparently in C# 2.0 with the introduction of nullable types (Nullable<T>), C# grew an operator:


int? x = null;
int? y = x ?? 0;

?? is a binary operator that returns the left value if it is not null, otherwise the right value.

Wacky!
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Joe[x86]

I can only thing of a single use for this:

String errorMessage404 = localizedString("error404", "es") ?? "Error 404: File not found."

I'm sure there must be some other uses, but none seem obvious.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joex86] link=topic=16128.msg162518#msg162518 date=1165969018]
I can only thing of a single use for this:

String errorMessage404 = localizedString("error404", "es") ?? "Error 404: File not found."

I'm sure there must be some other uses, but none seem obvious.

......
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Hero

Quote from: MyndFyre[vL] on December 12, 2006, 08:00 PM
Quote from: Joex86] link=topic=16128.msg162518#msg162518 date=1165969018]
I can only thing of a single use for this:

String errorMessage404 = localizedString("error404", "es") ?? "Error 404: File not found."

I'm sure there must be some other uses, but none seem obvious.

......
Exactly what I was thinking....

Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

Quote from: Joex86] link=topic=16128.msg162554#msg162554 date=1166026656]
So, what did I miss?

Indeed, heRo, what did he miss?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Hero

Quote from: MyndFyre[vL] on December 13, 2006, 05:13 PM
Quote from: Joex86] link=topic=16128.msg162554#msg162554 date=1166026656]
So, what did I miss?

Indeed, heRo, what did he miss?
I never said he missed anything...

Warrior

Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Explicit

I'm awake in the infinite cold.

[13:41:45]<@Fapiko> Why is TehUser asking for wang pictures?
[13:42:03]<@TehUser> I wasn't asking for wang pictures, I was looking at them.
[13:47:40]<@TehUser> Mine's fairly short.

shout


Imperceptus

just to save you from having to type an extra colon and a null in your code? seems slightly redundant from just ?
Quote from: Hazard on August 07, 2003, 03:15 PM
Highlight your entire code. Press the delete key. Start over again using Cuphead's CSB tutorial and work your way from their rather than raping code from downloaded sources meant purely for learning purposes. If this does not fix the problem, uninstall Visual Basic and get a new hobby. I suggest Cricket.

MyndFyre

Quote from: Imperceptus on December 15, 2006, 01:18 PM
just to save you from having to type an extra colon and a null in your code? seems slightly redundant from just ?

string val = x ?? "null x";
string val = x == null ? "null x" : x;


I think the first is much clearer in intent.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.