I have a class Items
public class Items
{
public int A1 { get; set; }
public int B1 { get; set; }
//...
public int A9 { get; set; }
public int B9 { get; set; }
}
and i have to compare properties (A1
and B1
, A2
and B2
and so on)
in case that Bx > Ax
i need to swap them - here is my method:
public static void Swap(ref int a, ref int b)
{
if (a > b)
{
int Temp = a;
a = b;
b = Temp;
}
}
but that way the application doesn't compile:
Items i1 = new Items() { A1 = 2010, B1 = 2000 };
Swap(ref i1.A1,ref i1.B1);
Error says that ref
or out
can't be used on properties. is there a better/cleaner way to handle this?