?? Operator

?? Operator

The ?? operator, sometimes called the Coalescing Operator, is a binary operator that is part of the syntax for a basic conditional expression in several programming languages, most notably C#.

Conditional assignment

?? is most frequently used to simplify null expressions as follows:

"possibly_null_value" ?? "value_if_null"

The "possibly_null_value" is evaluated "true" or "false" as a Boolean expression. On the basis of the evaluation of the Boolean condition, the entire expression returns "value_if_null" when "possibly_null_value" is null, but "possibly_null_value" otherwise. This is similar to the way ternary operators (?: statements) work in functional programming languages.

This operator's most common usage is to minimize the amount of code used for a simple null check. For example, if we wish to implement some C# code to give a page a default title if none is present, we may use the following statement:

string pageTitle = suppliedTitle ?? "Default Title";

instead of the more verbosestring pageTitle = (suppliedTitle = null) ? "Default Title" : suppliedTitle;orstring pageTitle;

if (suppliedTitle = null) pageTitle = "Default Title";else pageTitle = suppliedTitle;The three forms are equivalent.

JavaScript Implementation

In JavaScript, the equivalent of this is:/* pre: assume that "foo" does not exist
*/

var bar=(document.foo) || "goo";

/* post: "bar" now has a value of "goo".
*/

ee also

*?:
*C#

External links

* [http://blog.devstone.com/Aaron/archive/2006/01/02/1404.aspx New Operator in C# 2.0: ?? (null coalescing operator)]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Operator — Operator …   Deutsch Wörterbuch

  • Operator — may refer to: Contents 1 Music 2 Computers 3 Science and mathematics …   Wikipedia

  • operator — op‧e‧ra‧tor [ˈɒpəreɪtə ǁ ˈɑːpəreɪtər] noun [countable] 1. JOBS MANUFACTURING someone who works a machine or piece of equipment: • a computer operator • This machine requires a skilled operator. 2. a person or company that operates a particu …   Financial and business terms

  • Operator — (v. lat.) hat folgende Bedeutungen: Operator im Sinne der Mathematik: Operator (Mathematik), eine Vorschrift in der Mathematik Linearer Operator ist in der Funktionalanalysis (einem Teilgebiet der Mathematik) synonym zum Begriff der Lineare… …   Deutsch Wikipedia

  • operator — OPERATÓR, OÁRE, operatori, oare s., adj. 1. s.m. şi f. Muncitor calificat care supraveghează funcţionarea unei maşini de lucru, a unui aparat sau care efectuează diverse operaţii cu acestea. ♦ spec. Persoană care mânuieşte aparatul de luat vederi …   Dicționar Român

  • OperaTor — Стартовая страница браузера Тип Браузер Разработчик …   Википедия

  • Operator — «Operator» Sencillo de Blue System del álbum Backstreet Dreams Formato 7 Sencillo y CD Maxi Grabación 1992 Género(s) Synthpop Duración 3:13 …   Wikipedia Español

  • OperaTor — Maintainer: Arche Twist Entwickler: Arche Twist Aktuelle Version: 3.2 (29. August 2008) Betriebssystem …   Deutsch Wikipedia

  • Operator 13 — Directed by Richard Boleslawski Written by Robert W Chambers Harvey F Thew Eve Greene Starring Marion Davies Gary Cooper Jean Parker …   Wikipedia

  • operator — opèrātor (operȃtor) m DEFINICIJA 1. mat. funkcija čija su domena i kodomena vektorski prostori [linearni operator] 2. log. a. simbol za određene računske operacije i funkcije [aritmetički operator] b. izraz koji pretpostavlja neku logičku… …   Hrvatski jezični portal

  • operator — I {{/stl 13}}{{stl 8}}rz. mos I, Mc. operatororze; lm M. operatororzy {{/stl 8}}{{stl 20}} {{/stl 20}}{{stl 12}}1. {{/stl 12}}{{stl 7}} chirurg przeprowadzający operację {{/stl 7}}{{stl 20}} {{/stl 20}}{{stl 12}}2. {{/stl 12}}{{stl 7}} członek… …   Langenscheidt Polski wyjaśnień

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”