Skip to content

To make "Assign if variable is not null, otherwise skip" be shorter #49427

Answered by PathogenDavid
Flithor asked this question in Ideas
Discussion options

You must be logged in to vote

As @canton7 noted on your csharplang question, IL doesn't really matter. What matters is what the JIT emits. If you compare the JIT assembly for your two code snippets, the generated code is essentially the same:

; Using ??
C.M1(System.Object, System.Object)
    L0000: test rdx, rdx
    L0003: jne short L0008
    L0005: mov rdx, r8
    L0008: mov rax, rdx
    L000b: ret

; Using if
C.M2(System.Object, System.Object)
    L0000: test rdx, rdx
    L0003: je short L0008
    L0005: mov r8, rdx
    L0008: mov rax, r8
    L000b: ret

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@canton7
Comment options

Answer selected by Flithor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
3 participants