<p>I want alwaysPositive to be assigned a positive number with all possible values for lareValue1 and largeValue2 (these are at least 1).</p>

<p>The following statement causes a buffer overflow:</p>

<pre><code>int alwaysPositive = (largeValue1 + largeValue2) / 2;
</code></pre>

<p>I know I can prevent it by substracting and adding:</p>

<pre><code>int alwaysPositive = largeValue1 + ((largeValue2 - largeValue1) / 2);
</code></pre>

<p>But in other programming languages I can use an unsigned bitshift to do the trick:</p>

<pre><code>int alwaysPositive3 = (largeValue1 + largeValue2) &gt;&gt;&gt; 1;
</code></pre>

<p>How can I do this in C#?</p>

<hr>

<p>The answers below all solve the problem. There are probably lots of ways to do this, but they all (including my solutions) have one thing in common: they all look obfuscated. </p>

You could use uints:
```
```
uint alwaysPositive = (uint)(largeValue1 + largeValue2) / 2;
```
```