{"id":12984,"date":"2023-01-11T18:29:29","date_gmt":"2023-01-11T10:29:29","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=12984"},"modified":"2023-01-11T18:43:32","modified_gmt":"2023-01-11T10:43:32","slug":"%e5%ad%97%e6%ae%b5%e9%99%90%e5%ae%9a%e7%ac%a6%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/12984.html","title":{"rendered":"\u5b57\u6bb5\u9650\u5b9a\u7b26\u6709\u54ea\u4e9b"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u5b57\u6bb5\u9650\u5b9a\u7b26\u6709\uff1a1. Abstract\uff1b2. Const\uff1b3. Event\uff1b4. Extern\uff1b5. Override\u3002\u5176\u4e2d\uff0cabstract \u9650\u5b9a\u7b26\u88ab\u7528\u4e8e\u7c7b\u3001\u65b9\u6cd5\u4ee5\u53ca\u5c5e\u6027\u3002\u5728\u7c7b\u5b9a\u4e49\u4e2d\u4f7f\u7528abstract \u9650\u5b9a\u7b26\uff0c\u8868\u660e\u8be5\u7c7b\u4ec5\u4ec5\u7528\u6765\u4f5c\u4e3a\u5176\u4ed6\u7c7b\u7684\u57fa\u7c7b\u3002<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"680\" height=\"421\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/01\/\u9ed8\u8ba4\u6807\u9898__2023-01-10-16_27_28.png?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-12986\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/01\/\u9ed8\u8ba4\u6807\u9898__2023-01-10-16_27_28.png 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/01\/\u9ed8\u8ba4\u6807\u9898__2023-01-10-16_27_28-300x186.png 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u5b57\u6bb5\u9650\u5b9a\u7b26<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Abstract<\/strong><\/h3>\n\n\n\n<p>abstract \u9650\u5b9a\u7b26\u88ab\u7528\u4e8e\u7c7b\u3001\u65b9\u6cd5\u4ee5\u53ca\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>\u5728\u7c7b\u5b9a\u4e49\u4e2d\u4f7f\u7528abstract \u9650\u5b9a\u7b26\uff0c\u8868\u660e\u8be5\u7c7b\u4ec5\u4ec5\u7528\u6765\u4f5c\u4e3a\u5176\u4ed6\u7c7b\u7684\u57fa\u7c7b\u3002<\/p>\n\n\n\n<p>\u62bd\u8c61\u7c7b\u6709\u4ee5\u4e0b\u7279\u5f81\uff1a<\/p>\n\n\n\n<p>\u62bd\u8c61\u7c7b\u662f\u4e0d\u80fd\u88ab\u4f8b\u793a\u7684\u3002<\/p>\n\n\n\n<p>\u62bd\u8c61\u7c7b\u53ef\u4ee5\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\u548c\u5b58\u53d6\u5668\u3002<\/p>\n\n\n\n<p>\u4e0d\u53ef\u80fd\u7528\u88ab\u5c01\u88c5\u7684\u9650\u5b9a\u7b26\u4fee\u6539\u62bd\u8c61\u7c7b\uff0c\u5373\u8be5\u7c7b\u4e0d\u80fd\u88ab\u7ee7\u627f\u3002<\/p>\n\n\n\n<p>\u7531\u62bd\u8c61\u7c7b\u7ee7\u627f\u800c\u6765\u7684\u975e\u62bd\u8c61\u7c7b\u5fc5\u987b\u5305\u62ec\u6240\u6709\u6d3e\u751f\u62bd\u8c61\u65b9\u6cd5\u548c\u5b58\u53d6\u5668\u7684\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n\n\n\n<p>\u65b9\u6cd5\u6216\u5c5e\u6027\u58f0\u660e\u4e2d\u7684\u62bd\u8c61\u9650\u5b9a\u7b26\u7528\u6765\u6307\u660e\u8be5\u65b9\u6cd5\u6216\u5c5e\u6027\u4e2d\u4e0d\u5305\u542b\u5b9e\u9645\u5e94\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Const<\/strong><\/h3>\n\n\n\n<p>\u5173\u952e\u5b57const \u7528\u6765\u4fee\u6539\u4e00\u4e2a\u57df\u6216\u672c\u5730\u53d8\u91cf\u7684\u58f0\u660e\u3002\u5b83\u5c06\u8be5\u57df\u6216\u672c\u5730\u53d8\u91cf\u7684\u503c\u6307\u5b9a\u4e3a\u4e0d\u53ef\u4fee\u6539\u3002\u5e38\u91cf\u58f0\u660e\u4ecb\u7ecd\u4e86\u7ed9\u5b9a\u7c7b\u578b\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5e38\u91cf\u3002\u58f0\u660e\u91c7\u7528\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n\n\n\n<p>[attributes] [modifiers] const type declarators;<\/p>\n\n\n\n<p>\u5176\u4e2d\uff0cattributes (\u53ef\u9009)\u53ef\u9009\u62e9\u7684\u58f0\u660e\u4fe1\u606f\u3002modifiers (\u53ef\u9009)\u53ef\u9009\u62e9\u7684\u9650\u5b9a\u7b26\uff0c\u5305\u542b\u65b0\u7684\u9650\u5b9a\u7b26\u548c4\u4e2a\u8bbf\u95ee\u9650\u5b9a\u7b26(access modifiers)\u4e4b\u4e00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Event<\/strong><\/h3>\n\n\n\n<p>\u6307\u5b9a\u4e8b\u4ef6\u3002<\/p>\n\n\n\n<p>[attributes] [modifiers] event type declarator;<\/p>\n\n\n\n<p>[attributes] [modifiers] event type member-name {accessor-declarations};<\/p>\n\n\n\n<p>\u5176\u4e2d\uff1a<\/p>\n\n\n\n<p>accessor-declarations<\/p>\n\n\n\n<p>property accessors\u7684\u58f0\u660e, \u7528\u6765\u8bfb\u5199\u5c5e\u6027\u3002<\/p>\n\n\n\n<p>attributes (\u53ef\u9009)<\/p>\n\n\n\n<p>\u53ef\u9009\u58f0\u660e\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>declarator<\/p>\n\n\n\n<p>\u4e8b\u4ef6\u540d\u79f0\u3002<\/p>\n\n\n\n<p>member-name<\/p>\n\n\n\n<p>\u4e8b\u4ef6\u5c5e\u6027\u540d\u79f0\u3002<\/p>\n\n\n\n<p>modifiers (\u53ef\u9009)<\/p>\n\n\n\n<p>\u53ef\u9009\u9650\u5b9a\u7b26\uff0c\u5305\u62ecnew(\u65b0), static(\u9759\u6001), \u4ee5\u53ca 4 \u4e2aaccess modifiers(\u8bbf\u95ee\u9650\u5b9a\u7b26)\u4e4b\u4e00\u3002<\/p>\n\n\n\n<p>type<\/p>\n\n\n\n<p>\u5e0c\u671b\u7528\u6765\u8054\u7cfb\u4e8b\u4ef6\u7684\u4ee3\u8868\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Extern<\/strong><\/h3>\n\n\n\n<p>\u5728\u65b9\u6cd5\u58f0\u660e\u4e2d\u4f7f\u7528 extern\u9650\u5b9a\u7b26\uff0c\u6307\u660e\u8be5\u65b9\u6cd5\u662f\u5916\u90e8\u5b9e\u73b0\u7684\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5916\u90e8\u9650\u5b9a\u7b26\u90fd\u548cDllImport\u5c5e\u6027\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u5c06abstract(\u62bd\u8c61)\u548cextern(\u5916\u90e8)\u9650\u5b9a\u7b26\u653e\u5728\u4e00\u8d77\u4fee\u9970\u76f8\u540c\u6210\u5458\u662f\u9519\u8bef\u7684\u3002\u4f7f\u7528 extern\u9650\u5b9a\u7b26\u610f\u5473\u7740\u8be5\u65b9\u6cd5\u5728 C#\u5916\u90e8\u5b9e\u65bd\uff0c\u800c\u4f7f\u7528 abstract \u9650\u5b9a\u7b26\u7684\u610f\u601d\u662f\u7c7b\u4e2d\u4e0d\u63d0\u4f9b\u8be5\u65b9\u6cd5\u7684\u5b9e\u65bd\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a\u5916\u90e8\u65b9\u6cd5\u58f0\u660e\u4e0d\u63d0\u4f9b\u5b9e\u9645\u5e94\u7528\uff0c\u6240\u4ee5\u6ca1\u6709\u65b9\u6cd5\u4f53\uff1b\u65b9\u6cd5\u58f0\u660e\u7b80\u5355\u5730\u7531\u5206\u53f7\u7ed3\u675f\uff0c\u5e76\u4e14\u5728\u7b7e\u540d\u540e\u6ca1\u6709\u62ec\u53f7({ })\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Override<\/strong><\/h3>\n\n\n\n<p>override \u9650\u5b9a\u7b26\u7528\u6765\u4fee\u6539\u65b9\u6cd5\u6216\u5c5e\u6027\u3002\u8986\u76d6\u65b9\u6cd5\u4e3a\u4ece\u57fa\u7c7b\u7ee7\u627f\u7684\u6210\u5458\u63d0\u4f9b\u65b0\u7684\u5e94\u7528\u3002\u88ab\u8986\u76d6\u58f0\u660e\u6240\u8986\u76d6\u7684\u65b9\u6cd5\u79f0\u4e4b\u4e3a\u88ab\u8986\u76d6\u5e93\u65b9\u6cd5(overridden base method)\u3002\u88ab\u8986\u76d6\u5e93\u65b9\u6cd5\u5fc5\u987b\u4e0e\u8986\u76d6\u65b9\u6cd5\u6709\u76f8\u540c\u7684\u7b7e\u540d\u3002<\/p>\n\n\n\n<p>\u975e\u865a\u62df\u6216\u8005\u9759\u6001\u65b9\u6cd5\u662f\u4e0d\u80fd\u88ab\u8986\u76d6\u7684\u3002\u88ab\u8986\u76d6\u7c7b\u65b9\u6cd5\u5fc5\u987b\u662f\u865a\u62df\u3001\u62bd\u8c61\u6216\u8986\u76d6\u65b9\u6cd5\u3002\u8986\u76d6\u58f0\u660e\u4e0d\u80fd\u6539\u53d8\u865a\u62df\u65b9\u6cd5\u7684\u53ef\u8bbf\u95ee\u6027\u3002\u8986\u76d6\u65b9\u6cd5\u548c\u865a\u62df\u65b9\u6cd5\u90fd\u5fc5\u987b\u6709\u76f8\u540c\u7684\u8bbf\u95ee\u7ea7\u522b\u9650\u5b9a\u7b26\u3002<\/p>\n\n\n\n<p>\u4e0d\u80fd\u4f7f\u7528\u4e0b\u5217\u9650\u5b9a\u7b26\u5bf9\u8986\u76d6\u65b9\u6cd5\u8fdb\u884c\u4fee\u6539\uff1a<\/p>\n\n\n\n<p>new static virtual abstract (\u65b0\u3001\u9759\u6001\u3001\u865a\u62df\u3001\u62bd\u8c61)<\/p>\n\n\n\n<p>\u8986\u76d6\u5c5e\u6027\u58f0\u660e\u6307\u5b9a\u7684\u8bbf\u95ee\u9650\u5b9a\u7b26\u3001\u7c7b\u578b\u548c\u540d\u5b57\u5fc5\u987b\u4e0e\u88ab\u7ee7\u627f\u5c5e\u6027\u5b8c\u5168\u76f8\u540c\uff0c\u88ab\u8986\u76d6\u5c5e\u6027\u5fc5\u987b\u662f\u865a\u62df\u3001\u62bd\u8c61\u6216\u662f\u8986\u76d6\u3002<\/p>\n\n\n\n<p><strong>\u5ef6\u4f38\u9605\u8bfb\uff1a<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001static\u9650\u5b9a\u7b26<\/strong><\/h2>\n\n\n\n<p>\u4f7f\u7528 static \u9650\u5b9a\u7b26\u53ef\u4ee5\u58f0\u660e\u9759\u6001\u6210\u5458\uff0c\u9759\u6001\u6210\u5458\u5c5e\u4e8e\u7c7b\u578b\u672c\u8eab\u800c\u4e0d\u5c5e\u4e8e\u7279\u5b9a\u7684\u5bf9\u8c61\u3002Static \u9650\u5b9a\u7b26\u53ef\u4ee5\u5728\u5b57\u6bb5\u3001\u65b9\u6cd5\u3001\u5c5e\u6027\u3001\u64cd\u4f5c\u7b26\u548c\u6784\u9020\u51fd\u6570\u4e2d\u4f7f\u7528\uff0c\u4f46\u662f\u4e0d\u80fd\u5728\u7d22\u5f15\u5668\u3001\u6790\u6784\u51fd\u6570\u6216\u8005\u7c7b\u578b\u4e2d\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u8bf4\u660e\uff1a<\/p>\n\n\n\n<p>1. \u5e38\u91cf\u6216\u8005\u7c7b\u578b\u58f0\u660e\u662f\u9690\u5f0f\u9759\u6001\u6210\u5458\u3002<\/p>\n\n\n\n<p>2. \u9759\u6001\u6210\u5458\u4e0d\u80fd\u901a\u8fc7\u5b9e\u4f8b\u8fdb\u884c\u5f15\u7528\uff0c\u800c\u5e94\u8be5\u901a\u8fc7\u7c7b\u578b\u540d\u79f0\u5f15\u7528\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5c31\u662f\u5173\u4e8e\u5b57\u7b26\u9650\u5b9a\u7b26\u7684\u5185\u5bb9\u5e0c\u671b\u5bf9\u5927\u5bb6\u6709\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b57\u6bb5\u9650\u5b9a\u7b26\u6709\uff1a1. Abstract\uff1b2. Const\uff1b3. Event\uff1b4. Extern\uff1b5. Overr [&hellip;]","protected":false},"author":1,"featured_media":12986,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/12984"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=12984"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/12984\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/12986"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=12984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=12984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=12984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}