How to swap property values in ViewModel? Can't pass by ref
<p>I'd like to compare and swap the values of two ViewModel public properties, ideally using a method like this:</p>

<pre><code>void SwapIfGreater&lt;T&gt;(ref T lhs, ref T rhs) where T : System.IComparable&lt;T&gt;
{
    T temp;
    if (lhs.CompareTo(rhs) &gt; 0)
    {
        temp = lhs;
        lhs = rhs;
        rhs = temp;
    }
}
</code></pre>

<p>But as you can't pass properties by ref, I can't do this in my ViewModel.</p>

<pre><code>private Int32 max;
public Int32 Max
{
    get { return max; }
    set
    {
        SwapIfGreater&lt;Int32&gt;(ref Min, ref Max);
        max = value;
        OnPropertyChanged("Max");
    }
}

private Int32 min;
public Int32 Min
{
    get { return min; }
    set
    {
        SwapIfGreater&lt;Int32&gt;(ref Min, ref Max);
        min = value;
        OnPropertyChanged("Min");
    }
}
</code></pre>

<p>Failing that... if I just try to use the "if compare" logic directly within the Min getter or setter, when Min is changed to a value greater than Max, I just end up with Min equal to Max.</p>

<p><strong>EDIT</strong>: Based upon the advice about backing properties I've amended the method to this:</p>

<pre><code>void SwapIfGreater&lt;T&gt;(ref T lhs, ref T rhs, String otherPropertyName) where T : System.IComparable&lt;T&gt;
{
    T temp;
    if (lhs.CompareTo(rhs) &gt; 0)
    {
        temp = lhs;
        lhs = rhs;
        rhs = temp;
        OnPropertyChanged(otherPropertyName);
    }            
}
</code></pre>

<p>and the "Min" Property setter to this:</p>

<pre><code>    min = value;
    SwapIfGreater&lt;Int32&gt;(ref min, ref max, "Max");                
    OnPropertyChanged("Min");
</code></pre>

<p>What am I missing? This is still just setting Max to Min when Min is greater than Max.</p>

<p><strong>EDIT</strong>: Although I'm keen to learn what I'm doing wrong above, having tested the UI again which implements the swap behaviour I wanted to replicate, I've realised it's a nasty UX, as the user is force to then click both pickers again. I'm going to revert to my original implementation of resetting Max to "No Maximum" if the user selects a Min higher than Max and vice versa.</p>