02.09.2019»»понедельник

Question Mark Guy

02.09.2019
    98 - Comments
  1. Matthew Lesko Scam Customer Reviews

Guy with question mark suit? He was on a commercial advertising some book that told you how to get government grants and all sorts of 'free' money. What was the name of that book? Would you marry the question mark suit guy from the commercials? You know those infomercials with the guy with the question marks on his suit??? More questions.

Active7 months ago

Ran across this line of code:

What do the two question marks mean, is it some kind of ternary operator?It's hard to look up in Google.

Igor Kustov
2,5002 gold badges27 silver badges28 bronze badges
Edward TanguayEdward Tanguay
83.2k275 gold badges657 silver badges993 bronze badges

17 Answers

It's the null coalescing operator, and quite like the ternary (immediate-if) operator. See also ?? Operator - MSDN.

expands to:

which further expands to:

In English, it means 'If whatever is to the left is not null, use that, otherwise use what's to the right.'

Note that you can use any number of these in sequence. The following statement will assign the first non-null Answer# to Answer (if all Answers are null then the Answer is null):

Also it's worth mentioning while the expansion above is conceptually equivalent, the result of each expression is only evaluated once. This is important if for example an expression is a method call with side effects. (Credit to @Joey for pointing this out.)

Kolappan Nathan
9512 gold badges17 silver badges25 bronze badges
lc.lc.
92.9k19 gold badges133 silver badges166 bronze badges

Just because no-one else has said the magic words yet: it's the null coalescing operator. It's defined in section 7.12 of the C# 3.0 language specification.

It's very handy, particularly because of the way it works when it's used multiple times in an expression. An expression of the form:

will give the result of expression a if it's non-null, otherwise try b, otherwise try c, otherwise try d. It short-circuits at every point.

Also, if the type of d is non-nullable, the type of the whole expression is non-nullable too.

Jon SkeetJon Skeet
1132k716 gold badges8198 silver badges8587 bronze badges

It's the null coalescing operator.

Yes, nearly impossible to search for unless you know what it's called! :-)

EDIT: And this is a cool feature from another question. You can chain them.

Community
Iain HolderIain Holder
10.8k10 gold badges60 silver badges84 bronze badges

Thanks everybody, here is the most succinct explanation I found on the MSDN site:

Edward TanguayEdward Tanguay
83.2k275 gold badges657 silver badges993 bronze badges

?? is there to provide a value for a nullable type when the value is null. So, if formsAuth is null, it will return new FormsAuthenticationWrapper().

Vishal Suthar
14.8k2 gold badges43 silver badges90 bronze badges
RedFilterRedFilter
140k31 gold badges251 silver badges258 bronze badges

The two question marks (??) indicate that its a Coalescing operator.

Coalescing operator returns the first NON-NULL value from a chain. You can see this youtube video which demonstrates the whole thing practically.

But let me add more to what the video says.

If you see the English meaning of coalescing it says “consolidate together”. For example below is a simple coalescing code which chains four strings.

So if str1 is null it will try str2, if str2 is null it will try str3 and so on until it finds a string with a non-null value.

In simple words Coalescing operator returns the first NON-NULL value from a chain.

Lonely Neuron
3,1343 gold badges18 silver badges35 bronze badges
Shivprasad KoiralaShivprasad Koirala
18.2k6 gold badges64 silver badges56 bronze badges

If you're familiar with Ruby, its = seems akin to C#'s ?? to me. Here's some Ruby:

And in C#:

Sarah VesselsSarah Vessels
15.2k27 gold badges135 silver badges212 bronze badges

It's short hand for the ternary operator.

Or for those who don't do ternary:

Jon Skeet
1132k716 gold badges8198 silver badges8587 bronze badges
Benjamin AutinBenjamin Autin
Vishal Suthar
14.8k2 gold badges43 silver badges90 bronze badges
akuaku
104k30 gold badges162 silver badges199 bronze badges

Nothing dangerous about this. In fact, it is beautiful. You can add default value if that is desirable, for example:

CODE

Agustin Meriles
4,2433 gold badges25 silver badges39 bronze badges
dqninhdqninh

As correctly pointed in numerous answers that is the 'null coalescing operator' (??), speaking of which you might also want to check out its cousin the 'Null-conditional Operator' (?. or ?[) that is an operator that many times it is used in conjunction with ??

Used to test for null before performing a member access (?.) or index (?[) operation. These operators help you write less code to handle null checks, especially for descending into data structures.

For example:

the old way without ?. and ?? of doing this is

which is more verbose and cumbersome.

brakeroobrakeroo

For your amusement only (knowing you are all C# guys ;-).

I think it originated in Smalltalk, where it has been around for many years. It is defined there as:

in Object:

in UndefinedObject (aka nil's class):

There are both evaluating (?) and non-evaluating versions (??) of this.
It is often found in getter-methods for lazy-initialized private (instance) variables, which are left nil until really needed.

blabla999blabla999

Some of the examples here of getting values using coalescing are inefficient.

What you really want is:

or

This prevents the object from being recreated every time. Instead of the private variable remaining null and a new object getting created on every request, this ensures the private variable is assigned if the new object is created.

KingOfHypocritesKingOfHypocrites

Matthew Lesko Scam Customer Reviews

5,0027 gold badges39 silver badges61 bronze badges

I have read whole this thread and many others but I can't find as thorough answer as this is.

By which I completely understood the 'why to use ?? and when to use ?? and how to use ??.'

Windows communication foundation unleashed By Craig McMurtryISBN 0-672-32948-4

There are two common circumstances in which one would like to know whethera value has been assigned to an instance of a value type. The first is when the instance represents a value in a database. In such a case, one would like to be able to examine the instance to ascertain whether a value is indeed present in the database. The other circumstance, which is more pertinent to the subject matter of this book, is when the instance represents a data item received from some remote source. Again, one would like to determine from the instance whether a value for that data item was received.

The .NET Framework 2.0 incorporates a generic type definition that provides for cases like these in which one wants to assign null to an instance of a value type, and test whether the value of the instance is null. That generic type definition is System.Nullable, which constrains the generic type arguments that may be substituted for T to value types.Instances of types constructed from System.Nullable can be assigned a value of null; indeed, their values are null by default. Thus, types constructed fromSystem.Nullable may be referred to as nullable value types.System.Nullable has a property, Value, by which the value assigned to an instance ofa type constructed from it can be obtained if the value of the instance is not null.Therefore, one can write:

The C# programming language provides an abbreviated syntax for declaring typesconstructed from System.Nullable. That syntax allows one to abbreviate:

to

The compiler will prevent one from attempting to assign the value of a nullable value type to an ordinary value type in this way:

It prevents one from doing so because the nullable value type could have the value null, which it actually would have in this case, and that value cannot be assigned to an ordinary value type. Although the compiler would permit this code,

The second statement would cause an exception to be thrown because any attempt toaccess the System.Nullable.Value property is an invalid operation if the typeconstructed from System.Nullable has not been assigned a valid value of T, which has not happened in this case.

One proper way to assign the value of a nullable value type to an ordinary value type is to use the System.Nullable.HasValue property to ascertain whether a valid value of T has been assigned to the nullable value type:

Another option is to use this syntax:

By which the ordinary integer myInteger is assigned the value of the nullable integer 'myNullableInteger' if the latter has been assigned a valid integer value; otherwise, myInteger is assigned the value of -1.

WiqiWiqi

is equivalent to

But the cool thing about it is you can chain them, like other people said.The one thin not touched upon is that you can actually use it to throw an exception.

NolePTRNolePTR

The ?? operator is called the null-coalescing operator. It returns the left-hand operand if the operand is not null; otherwise it returns the right hand operand.

Set variable2 to the value of variable1, if variable1 is NOT null;otherwise, if variable1 null, set variable2 to 100.

Adeel
2,2806 gold badges17 silver badges29 bronze badges
Jubayer HossainJubayer Hossain

It's a null coalescing operator that works similarly to a ternary operator.

Another interesting point for this is,'A nullable type can contain a value, or it can be undefined'.So if you try to assign a nullable value type to a non-nullable value type you will get a compile-time error.

So to do that using ?? operator:

Community
Ashish MishraAshish Mishra

protected by cs95Dec 20 '18 at 4:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged c#null-coalescing-operator or ask your own question.

This is part of 'Blockchain Decoded,' a series looking at the impact of blockchain, bitcoin and cryptocurrency on our lives.

You probably don't know the name Matthew Lesko, but you might recognize a man in a question mark suit holding wads of cash.

Lesko, an author based in Washington, DC, was a snapshot of the 1990s, much like Milli Vanilli and Pogs. He gained national recognition as the 'Question Mark Guy' for his Riddler-esque suits, which he wore in his commercials yelling about getting free money from the government.

If you're not familiar with his ads, here's a taste:

While his commercials disappeared with the decade, the promise of easy money remains. Consider the lure of cryptocurrency, a digital technology touted as an alternative to the money issued -- and regulated -- by governments. Bitcoin, the best known of the bunch, has soared in value over the last year, reaching a peak of nearly $20,000 in December before settling to about half that value in recent weeks.

But where there's the promise of a fast buck, there's also risk -- and sketchiness. Facebook recently banned ads for cryptocurrencies for being misleading. Buzzfeed published an article calling out James Altucher, a self-proclaimed bitcoin expert, and alleging deceptive practices. In an interview with Inc, Altucher denied the allegations.

Lesko said that with so-called blockchain experts today he sees the same exaggerations he used in his come-ons. In 2004, the New York State Consumer Protection Board criticized Lesko's commercials and books, writing that many of his readers couldn't get the 'free money' he promised.

I had an opportunity to chat with the Question Mark Guy and get his thoughts on how cryptocurrency experts today echo his antics from more than 20 years ago.

Q: What do you know about blockchain and cryptocurrency?
Lesko: I do a lot of online chats and live broadcasts, and so many people are interested in it. I really help people who want to get ahead in life and what programs are available, and so they ask about bitcoin.

If you're not an expert, this is a hell of a time to get involved in it. You're playing with sharks right now. This is the beginning of something, [and] no one knows where it's going.

Now playing:Watch this: Cryptojacking: The hot new hacker trick for easy money

If you have money to lose, OK, go ahead. But if you don't have money to lose, just stay away from stuff like this. These people who are running it, and hoping the market goes up, think about this 24/7 and they've been at it for months and months and months.

It's like going to the Super Bowl and thinking, 'Oh, this looks like a fun game, I'll just put on a helmet and go out and play.'

If you're not well-grounded in this information for months, it seems silly or close to stupid, if you don't have the money to lose.

You made your name in the '90s with books on government grants for virtually anything. Your books on 'free money' offered plenty of opportunities. Are there any for blockchain?
Lesko: There are grants for any kind of business. If you were starting your own cryptocurrency, yes. The government will help you get that money. Say you needed to invest in a gazillion computers, there are offices in the government that have free counselors that help you get that money.

There's nothing specific like, 'Let's pass a grant program for cryptocurrencies.' The people on Capitol Hill probably can't even spell that yet. But there's money to start businesses. It's the reason they have these programs, because you're going to create jobs.

Do you think cryptocurrencies are a scam?
Lesko: Realistically, it's that way. Everyone is hoping there's another sucker. It keeps going up as long as somebody else thinks it's worth more. It's all about getting in and getting out. A lot of the stock market is that way, so who the hell knows.

There's no regulation like in a dollar bill, it's not backed by anything that you can get the money back if someone screws you over. That's the other thing -- if there's no regulation, you get screwed, you get screwed.

Do you think the hype around cryptocurrency is a bubble?
Lesko: Yes, but it's their money, they can do what they want with it. The bad part of it is that it's playing on people who can't really afford it.

I don't mind the hype for people who can afford it. It's the hype for people who can't afford it, and they hurt themselves by getting involved in this, instead of selling something more real, developing a skill that can contribute to society.

How are people getting sucked into cryptocurrency?
Lesko: We're so good at selling in this country. This is our talent. It's not making shit, it's selling shit.

We can sell anything, and that's the problem. You become so good at selling, it doesn't matter what the hell you're selling. How do you guard against that? The average person is not equipped to deal with somebody who spends 24 hours a day thinking of every answer to a question you have.

You can't pick through that bubble yourself. They're thinking every day about what motivates you to give them money.

Get to know bitcoin and blockchain

But you made a living off being that person. Your commercials had a lot of energy and a lot of hyperbole. Do you see the same thing going on now with cryptocurrency?
Lesko: Yes, and that's unfortunate. I did it for the same reason they do, to get people's attention. Sometimes you don't have a lot of time to explain all the ifs, ands or buts on things.

But for me, what I do, is, I have a philosophy. If 10 years from now, you think I screwed you, I'll give you your money back. That's the honest thing to do.

Question Mark Guy

If bitcoin were around during your 'free money' book days, would you have been one of these salesmen?
Lesko: No. I wanted to show people the tools to improve their life. Bitcoin right now is a gamble. I don't see how that improves anybody's life, gambling.

So why haven't you written a book helping people with cryptocurrency and blockchain?
Lesko: I don't wanna write about cryptocurrency, I'm not sure it's of value yet. I know there's real programs to help people. I want to show people about the real help that's available. For someone in Arizona who's four or five months back on their mortgage, there's money for that.

But for them to invest in cryptocurrency [thinking that] because by the next payment, they're gonna have all that money, no, they're just going to lose that money.

Would you rather have $2,000 from a government grant or invest $2,000 in a cryptocurrency?
Lesko: Three weeks ago, you would have been right to invest in cryptocurrency. A week ago, you'd be wrong. That's why it's so unstable.

If someone in your family wanted to put half their life savings in a cryptocurrency, what would you say to them?
Lesko: Ha -- that they're stupid. If your life savings were $10 million and you lost $5 million, that wouldn't change your life much.

If your life savings were $10,000 and you lost $5,000, you could have done a lot with that.

Updated at 9:01 a.m. PT: To include details on James Altucher.

'Alexa, be more human': Inside Amazon's effort to make its voice assistant smarter, chattier and more like you.

Tech Enabled: CNET chronicles tech's role in providing new kinds of accessibility.

Price drops on our favorite products
 fullpacviva © 2019