Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 863053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:14:46+00:00 2026-05-15T09:14:46+00:00

Does the ?? operator in C# use shortcircuiting when evaluating? var result = myObject

  • 0

Does the ?? operator in C# use shortcircuiting when evaluating?

var result = myObject ?? ExpressionWithSideEffects();

When myObject is non-null, the result of ExpressionWithSideEffects() is not used, but will ExpressionWithSideEffects() be skipped completely?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:14:46+00:00Added an answer on May 15, 2026 at 9:14 am

    Yes it does. As ever, the C# language specification is the definitive source1.

    From the C# 3 spec, section 7.12 (v3 rather than 4, as the v4 spec goes into dynamic details which aren’t really relevant here):

    The type of the expression a ?? b depends on which implicit conversions are available between the types of the operands. In order of preference, the type of a ?? b is A0, A, or B, where A is the type of a, B is the type of b (provided that b has a type), and A0 is the underlying type of A if A is a nullable type, or A otherwise. Specifically, a ?? b is processed as
    follows:

    • If A is not a nullable type or a reference type, a compile-time error
      occurs.
    • If A is a nullable type and an implicit conversion exists from b to
      A0, the result type is A0. At
      run-time, a is first evaluated. If a
      is not null, a is unwrapped to type
      A0, and this becomes the result.
      Otherwise, b is evaluated and
      converted to type A0, and this becomes
      the result.
    • Otherwise, if an implicit conversion exists from b to A, the result type is
      A. At run-time, a is first evaluated.
      If a is not null, a becomes the
      result. Otherwise, b is evaluated and
      converted to type A, and this becomes
      the result.
    • Otherwise, if b has a type B and an implicit conversion exists from A0 to
      B, the result type is B. At run-time,
      a is first evaluated. If a is not
      null, a is unwrapped to type A0
      (unless A and A0 are the same type)
      and converted to type B, and this
      becomes the result. Otherwise, b is
      evaluated and becomes the result.
    • Otherwise, a and b are incompatible, and a compile-time error occurs.

    The second, third and fourth bullets are the relevant ones.


    1 There’s a philosophical discussion to be had about whether the compiler you happen to be using is the actual source of truth… is the truth about a language what it’s meant to do or what it currently does?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering why the second map declaration (using the diamond operator) does not
What does the /= operator in C# do and when is it used?
I want to use intersect operator (xpath 2.0) with xmllint, but can't make it
(I know what the scope resolution operator does, and how and when to use
I understand what the double not operator does in JavaScript . I'm curious about
In Java, the instanceof operator will only return false if comparing null . If
Why does C++ require that user-defined conversion operator can only be non-static member? Why
Does R have shorthand, function or operator which I can use to easily generate
The C++ STL does not seem to use purely abstract base classes (aka interfaces)
My version of SQLite does not support the IF EXISTS operator. How can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.