日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#操作符重載學(xué)習(xí)實(shí)踐操作

C#操作符重載學(xué)習(xí)實(shí)踐操作

成都創(chuàng)新互聯(lián)公司專注于企業(yè)成都營銷網(wǎng)站建設(shè)、網(wǎng)站重做改版、遂平網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為遂平等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

 
 
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication1
  6. {
  7. class MyCls
  8. {
  9. public int X
  10. {
  11. get;  //C#操作符重載
  12. set;
  13. }
  14. public int Y
  15. {
  16. get;
  17. set;
  18. }
  19. public override string ToString()
  20. {
  21. return string.Format("X={0},Y={1}", X, Y);
  22. }
  23. public override bool Equals(object obj)
  24. {
  25. MyCls a = obj as MyCls;
  26. return a.X == this.X && a.Y == this.Y;
  27. }
  28. public override int GetHashCode()
  29. {  //C#操作符重載
  30. return X * Y;
  31. }  
  32. public static MyCls operator +(MyCls a, MyCls b)
  33. {
  34. return new MyCls() { X = a.X + b.X, Y = a.Y + b.Y };
  35. }
  36. public static MyCls operator -(MyCls a, MyCls b)
  37. {
  38. return new MyCls { X = a.X - b.X, Y = a.Y - b.Y };
  39. }
  40. public static MyCls operator ++(MyCls a)
  41. {
  42. return new MyCls() { X = a.X++, Y = a.Y++ };
  43. }
  44. public static MyCls operator --(MyCls a)
  45. {
  46. return new MyCls() { X = a.X--, Y = a.Y-- };
  47. }
  48. public static bool operator ==(MyCls a, MyCls b)
  49. {
  50. return a.X == b.X && a.Y == b.Y;
  51. }
  52. public static bool operator !=(MyCls a, MyCls b)
  53. {  //C#操作符重載
  54. return a.X != b.X && a.Y != b.Y;
  55. }
  56. public static void Main()
  57. {
  58. MyCls a = new MyCls { X = 1, Y = 1 };
  59. MyCls b = new MyCls { X = 2, Y = 2 };
  60. Console.WriteLine(a + b);
  61. Console.WriteLine(b - a);
  62. Console.WriteLine(b++);
  63. Console.WriteLine(a--);
  64. Console.WriteLine(a++ == b);
  65. Console.WriteLine(a!= b--);
  66. Console.ReadLine();
  67. }  //C#操作符重載
  68. }
  69. }

C#操作符重載程序輸出結(jié)果:

 
 
 
  1. X=3,Y=3
  2. X=1,Y=1
  3. X=3,Y=3
  4. X=0,Y=0
  5. True
  6. False

C#操作符重載的學(xué)習(xí)應(yīng)用就向你介紹到這里,希望對你了解和學(xué)習(xí)C#操作符重載有所幫助。


本文標(biāo)題:C#操作符重載學(xué)習(xí)實(shí)踐操作
網(wǎng)頁路徑:http://www.dlmjj.cn/article/djdiidc.html