LeetCode: Sum of Two Integers C#
Your code is pretty much perfect, the only problem is that you chose to sacrifice some performance in most cases (non 0 operands) for the sake of making the rare case faster. Here's a slight improvement based on the assumption that most of the times none of the operands will be 0.

The trick is to keep it efficient in the case of 0 without wasting time on special checks that don't help the actual calculation. If the carry is 0 then you know you're done. Storing the output (a ^ b) in the same variable removes the need for an if statement for returning b instead of a.

Also 1 bitwise operation and assignment is saved by shifting the carry at the start of the loop, so there is no extra unused shift at the end. (note: it would slow the function down in case of overflow, but that's a rare case and it's expected that the programmer will avoid overflow anyway)

public int GetSum(int a, int b)
{
    int carry = a &amp; b;
    a = a ^ b;

    while (carry != 0)
    {
        b = carry &lt;&lt; 1;
        carry = a &amp; b;
        a = a ^ b;
    }

    return a;
}