Reputation: 3032
I want to discuss my problem clearly.
I have a function to Swap value of two variable
public static void Swap<T>(ref T first, ref T second)
{
T temp = first;
first = second;
second = temp;
}
I have use it in my code as this:
Swap<DateTime>(ref TarikhePayaneGozaresh, ref TarikheShorooeGhozaresh);
I have checked it many times and now I am confused.
As you can see the value didn't swaped!
Update : I have write more of my code.
Upvotes: 3
Views: 324
Reputation: 273199
Where exactly do you do the verification?
I notice that inside CalculateMablagheDariaftieKol()
you Swap a ref with a non-ref parameter.
So outside CalculateMablagheDariaftieKol()
you will not see a (complete) Swap.
Upvotes: 1
Reputation: 1062640
The swap works fine:
var TarikhePayaneGozaresh = DateTime.Parse("9/9/2010 12:00:00 AM");
var TarikheShorooeGharardad = DateTime.Parse("9/9/1991 12:00:00 AM");
Swap<DateTime>(ref TarikhePayaneGozaresh, ref TarikheShorooeGharardad);
Console.WriteLine(TarikhePayaneGozaresh); // 09/09/1991 00:00:00
Console.WriteLine(TarikheShorooeGharardad); //09/09/2010 00:00:00
I can only conclude that the problem is something outside of the code you have shown us, for example:
Upvotes: 4