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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#abstract修飾符淺析

C#語(yǔ)言有很多值得學(xué)習(xí)的地方,這里我們主要介紹C# abstract修飾符,包括介紹通常用于強(qiáng)制繼承類必須實(shí)現(xiàn)某一成員。等方面。

成都創(chuàng)新互聯(lián)是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設(shè)公司,自成立以來(lái)公司不斷探索創(chuàng)新,始終堅(jiān)持為客戶提供滿意周到的服務(wù),在本地打下了良好的口碑,在過(guò)去的10年時(shí)間我們累計(jì)服務(wù)了上千家以及全國(guó)政企客戶,如成都人造霧等企業(yè)單位,完善的項(xiàng)目管理流程,嚴(yán)格把控項(xiàng)目進(jìn)度與質(zhì)量監(jiān)控加上過(guò)硬的技術(shù)實(shí)力獲得客戶的一致稱揚(yáng)。

C# abstract修飾符是什么意思?

C# abstract修飾符可以用于類、方法、屬性、事件和索引指示器(indexer),表示其為抽象成員 abstract 不可以和 static 、virtual 一起使用聲明為 abstract 成員可以不包括實(shí)現(xiàn)代碼,但只要類中還有未實(shí)現(xiàn)的抽象成員(即抽象類),那么它的對(duì)象就不能被實(shí)例化,通常用于強(qiáng)制繼承類必須實(shí)現(xiàn)某一成員。

示例:

 
 
 
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Example04
  6. {
  7. #region 基類,抽象類
  8. public abstract class BaseClass
  9. {
  10. //抽象屬性,同時(shí)具有g(shù)et和set訪問(wèn)器表示繼承類必須將該屬性實(shí)現(xiàn)為可讀寫(xiě)
  11. public abstract String Attribute
  12. {
  13. get;
  14. set;
  15. }
  16.  
  17. //抽象方法,傳入一個(gè)字符串參數(shù)無(wú)返回值
  18. public abstract void Function(String value);
  19.  
  20. //抽象事件,類型為系統(tǒng)預(yù)定義的代理(delegate):EventHandler
  21. public abstract event EventHandler Event;
  22.  
  23. //抽象索引指示器,只具有g(shù)et訪問(wèn)器表示繼承類必須將該索引指示器實(shí)現(xiàn)為只讀
  24. public abstract Char this[int Index]
  25. {
  26. get;
  27. }
  28. }
  29. #endregion
  30.  
  31. #region 繼承類
  32. public class DeriveClass : BaseClass
  33. {
  34. private String attribute;
  35.  
  36. public override String Attribute
  37. {
  38. get
  39. {
  40. return attribute;
  41. }
  42. set
  43. {
  44. attribute = value;
  45. }
  46. }
  47. public override void Function(String value)
  48. {
  49. attribute = value;
  50. if (Event != null)
  51. {
  52. Event(this, new EventArgs());
  53. }
  54. }
  55. public override event EventHandler Event;
  56. public override Char this[int Index]
  57. {
  58. get
  59. {
  60. return attribute[Index];
  61. }
  62. }
  63. }
  64. #endregion
  65.  
  66. class Program
  67. {
  68. static void OnFunction(object sender, EventArgs e)
  69. {
  70. for (int i = 0; i < ((DeriveClass)sender).Attribute.Length; i++)
  71. {
  72. Console.WriteLine(((DeriveClass)sender)[i]);
  73. }
  74. }
  75. static void Main(string[] args)
  76. {
  77. DeriveClass tmpObj = new DeriveClass();
  78.  
  79. tmpObj.Attribute = "1234567";
  80. Console.WriteLine(tmpObj.Attribute);
  81.  
  82. //將靜態(tài)函數(shù)OnFunction與tmpObj對(duì)象的Event事件進(jìn)行關(guān)聯(lián)
  83. tmpObj.Event += new EventHandler(OnFunction);
  84.  
  85. tmpObj.Function("7654321");
  86.  
  87. Console.ReadLine();
  88. }
  89. }
  90. }

新聞標(biāo)題:C#abstract修飾符淺析
文章網(wǎng)址:http://www.dlmjj.cn/article/djdgeci.html