Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Swapper
- {
- public void Swap(ref double x, ref double y)
- {
- double temp = x; //copy x into temp
- x = y; //copy y into x
- y = temp; //copy temp into y (copy the original value of x into y)
- }
- static void Main()
- {
- Swapper switcher = new Swapper();
- var first = 10.5; var second = 10.6;
- Console.Write("first=" + first + "nsecond=" + second + "n"); // before swap
- switcher.Swap(ref first, ref second);
- Console.Write("first=" + first + "nsecond=" + second + "n"); // after swap
- }
- }
- class Swapper2
- {
- public void Swap2(ref dynamic x2, ref dynamic y2)
- {
- dynamic temp2 = x2;
- x2 = y2;
- y2 = temp2;
- }
- static void Main2()
- {
- Swapper2 switcher2 = new Swapper2();
- dynamic first2 = 6549744554; dynamic second2 = 10.6M;
- Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
- switcher2.Swap2(ref first2, ref second2);
- Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
- }
- }
- using System;
- class Swapper
- {
- public void Swap(ref double x, ref double y)
- {
- double temp = x; //copy x into temp
- x = y; //copy y into x
- y = temp; //copy temp into y (copy the original value of x into y)
- }
- public void Swap2(ref dynamic x2, ref dynamic y2)
- {
- dynamic temp2 = x2;
- x2 = y2;
- y2 = temp2;
- }
- static void Main()
- {
- Swapper switcher = new Swapper();
- var first = 10.5; var second = 10.6;
- Console.Write("first=" + first + "nsecond=" + second + "n"); // before swap
- switcher.Swap(ref first, ref second);
- Console.Write("first=" + first + "nsecond=" + second + "n"); // after swap
- Swapper switcher2 = new Swapper();
- dynamic first2 = 6549744554; dynamic second2 = 10.6M;
- Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
- switcher2.Swap2(ref first2, ref second2);
- Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
- }
- }
Add Comment
Please, Sign In to add comment