Guest User

Untitled

a guest
Jan 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. using System;
  2. class Swapper
  3. {
  4. public void Swap(ref double x, ref double y)
  5.  
  6. {
  7. double temp = x; //copy x into temp
  8. x = y; //copy y into x
  9. y = temp; //copy temp into y (copy the original value of x into y)
  10. }
  11. static void Main()
  12. {
  13. Swapper switcher = new Swapper();
  14. var first = 10.5; var second = 10.6;
  15. Console.Write("first=" + first + "nsecond=" + second + "n"); // before swap
  16. switcher.Swap(ref first, ref second);
  17. Console.Write("first=" + first + "nsecond=" + second + "n"); // after swap
  18.  
  19. }
  20. }
  21.  
  22. class Swapper2
  23. {
  24. public void Swap2(ref dynamic x2, ref dynamic y2)
  25. {
  26. dynamic temp2 = x2;
  27. x2 = y2;
  28. y2 = temp2;
  29. }
  30.  
  31. static void Main2()
  32. {
  33. Swapper2 switcher2 = new Swapper2();
  34. dynamic first2 = 6549744554; dynamic second2 = 10.6M;
  35. Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
  36. switcher2.Swap2(ref first2, ref second2);
  37. Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
  38.  
  39. }
  40. }
  41.  
  42. using System;
  43.  
  44. class Swapper
  45. {
  46. public void Swap(ref double x, ref double y)
  47.  
  48. {
  49. double temp = x; //copy x into temp
  50. x = y; //copy y into x
  51. y = temp; //copy temp into y (copy the original value of x into y)
  52. }
  53.  
  54. public void Swap2(ref dynamic x2, ref dynamic y2)
  55.  
  56. {
  57. dynamic temp2 = x2;
  58. x2 = y2;
  59. y2 = temp2;
  60. }
  61.  
  62. static void Main()
  63. {
  64. Swapper switcher = new Swapper();
  65. var first = 10.5; var second = 10.6;
  66. Console.Write("first=" + first + "nsecond=" + second + "n"); // before swap
  67. switcher.Swap(ref first, ref second);
  68. Console.Write("first=" + first + "nsecond=" + second + "n"); // after swap
  69.  
  70.  
  71. Swapper switcher2 = new Swapper();
  72. dynamic first2 = 6549744554; dynamic second2 = 10.6M;
  73. Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
  74. switcher2.Swap2(ref first2, ref second2);
  75. Console.Write("first=" + first2 + "nsecond=" + second2 + "n");
  76.  
  77. }
  78. }
Add Comment
Please, Sign In to add comment