-1

** Please stop to devote this question. I really don't know what to search for it. I have tried to use keyword like 'C# ??' and tried in the title of the qeustion like '?? what it ' but there is no any question in the 'Questions that may already have your answer' box.

public ICommand _command;
public ICommand Command
{
    get
    {
        return _command ?? (_command = new MvxCommand(AddItem));
    }
}

I found i like those code. But I really don't know what does it mean?

Additional, if i want to search in msdn about it, what the keyword I should use for?

user3089631
  • 169
  • 1
  • 7

3 Answers3

4

It is called a Null coalescing operator

if the first part is null then use the next part, in your case if _command is null then it creates a new command else it would use _command only

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
1

it's Null coalescing operator. It means if this has a value use it, if not use the next item.

It's very useful for nullable types and objects.

int? age = null; 

var defaultAge = age ?? 21;
//defaultAge is now 21

http://msdn.microsoft.com/en-us/library/ms173224.aspx

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96
-1

Null Coalesce operator. Functions just like, "IsNull" in TSQL. If the left value is not null, use it. Otherwise, use the right value.

Justin Russo
  • 2,214
  • 1
  • 22
  • 26