It's the null-coalescing operator.
It returns the first argument unless it is null, in which case it returns the second.
x ?? y
is roughly equivalent to this (except that the first argument is only evaluated once):
if (x == null)
{
result = y;
}
else
{
result = x;
}
Or alternatively:
(x == null) ? y : x
It is useful for providing a default value for when a value can be null:
Color color = user.FavouriteColor ?? defaultColor;
COALESCE
When used in a LINQ to SQL query the ??
operator can be translated to a call to COALESCE. For example this LINQ query:
var query = dataContext.Table1.Select(x => x.Col1 ?? "default");
can result in this SQL query:
SELECT COALESCE([t0].[col1],@p0) AS [value]
FROM [dbo].[table1] AS [t0]