{"id":232222,"date":"2021-12-26T09:56:15","date_gmt":"2021-12-26T01:56:15","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=232222"},"modified":"2021-12-17T10:56:55","modified_gmt":"2021-12-17T02:56:55","slug":"understand-the-basic-2","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/understand-the-basic-2.html","title":{"rendered":"\u4e86\u89e3\u4e0bC# \u57fa\u672c\u8bed\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nC# \u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u5728\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u65b9\u6cd5\u4e2d\uff0c\u7a0b\u5e8f\u7531\u5404\u79cd\u76f8\u4e92\u4ea4\u4e92\u7684\u5bf9\u8c61\u7ec4\u6210\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u76f8\u540c\u79cd\u7c7b\u7684\u5bf9\u8c61\u901a\u5e38\u5177\u6709\u76f8\u540c\u7684\u7c7b\u578b\uff0c\u6216\u8005\u8bf4\uff0c\u662f\u5728\u76f8\u540c\u7684 class \u4e2d\u3002<\/p>\n

\u4f8b\u5982\uff0c\u4ee5 Rectangle\uff08\u77e9\u5f62\uff09\u5bf9\u8c61\u4e3a\u4f8b\u3002\u5b83\u5177\u6709 length \u548c width \u5c5e\u6027\u3002\u6839\u636e\u8bbe\u8ba1\uff0c\u5b83\u53ef\u80fd\u9700\u8981\u63a5\u53d7\u8fd9\u4e9b\u5c5e\u6027\u503c\u3001\u8ba1\u7b97\u9762\u79ef\u548c\u663e\u793a\u7ec6\u8282\u3002<\/p>\n

\u8ba9\u6211\u4eec\u6765\u770b\u770b\u4e00\u4e2a Rectangle\uff08\u77e9\u5f62\uff09\u7c7b\u7684\u5b9e\u73b0\uff0c\u5e76\u501f\u6b64\u8ba8\u8bba C# \u7684\u57fa\u672c\u8bed\u6cd5\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

using<\/span> System<\/span>;\r\nnamespace<\/span> RectangleApplication\r\n{\r\n    class<\/span> Rectangle\r\n    {\r\n        \/\/ \u6210\u5458\u53d8\u91cf\r\n        double<\/span> length;\r\n        double<\/span> width;\r\n        public<\/span> void<\/span> Acceptdetails(<\/span>)\r\n        {\r\n            length =<\/span> 4.5<\/span>;<\/span>    \r\n            width =<\/span> 3.5<\/span>;\r\n        }\r\n        public<\/span> double<\/span> GetArea(<\/span>)\r\n        {\r\n            return<\/span> length *<\/span> width;\r\n        }\r\n        public<\/span> void<\/span> Display(<\/span>)\r\n        {\r\n            Console.<\/span>WriteLine<\/span>(<\/span>\"Length: {0}\"<\/span>, length)<\/span>;\r\n            Console.<\/span>WriteLine<\/span>(<\/span>\"Width: {0}\"<\/span>, width)<\/span>;\r\n            Console.<\/span>WriteLine<\/span>(<\/span>\"Area: {0}\"<\/span>, GetArea(<\/span>)<\/span>)<\/span>;\r\n        }\r\n    }\r\n    \r\n    class<\/span> ExecuteRectangle\r\n    {\r\n        static<\/span> void<\/span> Main(<\/span>string<\/span>[<\/span>]<\/span> args)\r\n        {\r\n            Rectangle r =<\/span> new<\/span> Rectangle(<\/span>)<\/span>;\r\n            r.<\/span>Acceptdetails<\/span>(<\/span>)<\/span>;\r\n            r.<\/span>Display<\/span>(<\/span>)<\/span>;\r\n            Console.<\/span>ReadLine<\/span>(<\/span>)<\/span>;\r\n        }\r\n    }\r\n}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n

\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u548c\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n

Length: 4.5\r\nWidth: 3.5\r\nArea: 15.75<\/pre>\n
using \u5173\u952e\u5b57<\/strong><\/div>\n

\u5728\u4efb\u4f55 C# \u7a0b\u5e8f\u4e2d\u7684\u7b2c\u4e00\u6761\u8bed\u53e5\u90fd\u662f\uff1a<\/p>\n

using System;<\/pre>\n

using \u5173\u952e\u5b57\u7528\u4e8e\u5728\u7a0b\u5e8f\u4e2d\u5305\u542b\u547d\u540d\u7a7a\u95f4\u3002\u4e00\u4e2a\u7a0b\u5e8f\u53ef\u4ee5\u5305\u542b\u591a\u4e2a using \u8bed\u53e5\u3002<\/p>\n

class \u5173\u952e\u5b57<\/strong><\/div>\n

class \u5173\u952e\u5b57\u7528\u4e8e\u58f0\u660e\u4e00\u4e2a\u7c7b\u3002<\/p>\n

C# \u4e2d\u7684\u6ce8\u91ca<\/strong><\/div>\n

\u6ce8\u91ca\u662f\u7528\u4e8e\u89e3\u91ca\u4ee3\u7801\u3002\u7f16\u8bd1\u5668\u4f1a\u5ffd\u7565\u6ce8\u91ca\u7684\u6761\u76ee\u3002\u5728 C# \u7a0b\u5e8f\u4e2d\uff0c\u591a\u884c\u6ce8\u91ca\u4ee5 \/* \u5f00\u59cb\uff0c\u5e76\u4ee5\u5b57\u7b26 *\/ \u7ec8\u6b62\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\/* This program demonstrates\r\nThe basic syntax of C# programming \r\nLanguage *\/<\/pre>\n

\u5355\u884c\u6ce8\u91ca\u662f\u7528 '\/\/' \u7b26\u53f7\u8868\u793a\u3002\u4f8b\u5982\uff1a<\/p>\n

}\/\/end class Rectangle<\/pre>\n
\u6210\u5458\u53d8\u91cf<\/strong><\/div>\n

\u53d8\u91cf\u662f\u7c7b\u7684\u5c5e\u6027\u6216\u6570\u636e\u6210\u5458\uff0c\u7528\u4e8e\u5b58\u50a8\u6570\u636e\u3002\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e2d\uff0cRectangle \u7c7b\u6709\u4e24\u4e2a\u6210\u5458\u53d8\u91cf\uff0c\u540d\u4e3a length \u548c width\u3002<\/p>\n

\u6210\u5458\u51fd\u6570<\/strong><\/div>\n

\u51fd\u6570\u662f\u4e00\u7cfb\u5217\u6267\u884c\u6307\u5b9a\u4efb\u52a1\u7684\u8bed\u53e5\u3002\u7c7b\u7684\u6210\u5458\u51fd\u6570\u662f\u5728\u7c7b\u5185\u58f0\u660e\u7684\u3002\u6211\u4eec\u4e3e\u4f8b\u7684\u7c7b Rectangle \u5305\u542b\u4e86\u4e09\u4e2a\u6210\u5458\u51fd\u6570\uff1a AcceptDetails\u3001GetArea \u548c Display\u3002<\/p>\n

\u5b9e\u4f8b\u5316\u4e00\u4e2a\u7c7b<\/strong><\/div>\n

\u5728\u4e0a\u9762\u7684\u7a0b\u5e8f\u4e2d\uff0c\u7c7b ExecuteRectangle \u662f\u4e00\u4e2a\u5305\u542b Main() \u65b9\u6cd5\u548c\u5b9e\u4f8b\u5316 Rectangle \u7c7b\u7684\u7c7b\u3002<\/p>\n

\u6807\u8bc6\u7b26<\/strong><\/div>\n

\u6807\u8bc6\u7b26\u662f\u7528\u6765\u8bc6\u522b\u7c7b\u3001\u53d8\u91cf\u3001\u51fd\u6570\u6216\u4efb\u4f55\u5176\u5b83\u7528\u6237\u5b9a\u4e49\u7684\u9879\u76ee\u3002\u5728 C# \u4e2d\uff0c\u7c7b\u7684\u547d\u540d\u5fc5\u987b\u9075\u5faa\u5982\u4e0b\u57fa\u672c\u89c4\u5219\uff1a<\/p>\n

    \n
  1. \u6807\u8bc6\u7b26\u5fc5\u987b\u4ee5\u5b57\u6bcd\u3001\u4e0b\u5212\u7ebf\u6216 @ \u5f00\u5934\uff0c\u540e\u9762\u53ef\u4ee5\u8ddf\u4e00\u7cfb\u5217\u7684\u5b57\u6bcd\u3001\u6570\u5b57\uff08 0 - 9 \uff09\u3001\u4e0b\u5212\u7ebf\uff08 _ \uff09\u3001@\u3002<\/li>\n
  2. \u6807\u8bc6\u7b26\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u80fd\u662f\u6570\u5b57\u3002<\/li>\n
  3. \u6807\u8bc6\u7b26\u5fc5\u987b\u4e0d\u5305\u542b\u4efb\u4f55\u5d4c\u5165\u7684\u7a7a\u683c\u6216\u7b26\u53f7\uff0c\u6bd4\u5982 ? - +! # % ^ & * ( ) [ ] { } . ; : \" ' \/ \\\u3002<\/li>\n
  4. \u6807\u8bc6\u7b26\u4e0d\u80fd\u662f C# \u5173\u952e\u5b57\u3002\u9664\u975e\u5b83\u4eec\u6709\u4e00\u4e2a @ \u524d\u7f00\u3002 \u4f8b\u5982\uff0c@if \u662f\u6709\u6548\u7684\u6807\u8bc6\u7b26\uff0c\u4f46 if \u4e0d\u662f\uff0c\u56e0\u4e3a if \u662f\u5173\u952e\u5b57\u3002<\/li>\n
  5. \u6807\u8bc6\u7b26\u5fc5\u987b\u533a\u5206\u5927\u5c0f\u5199\u3002\u5927\u5199\u5b57\u6bcd\u548c\u5c0f\u5199\u5b57\u6bcd\u88ab\u8ba4\u4e3a\u662f\u4e0d\u540c\u7684\u5b57\u6bcd\u3002<\/li>\n
  6. \u4e0d\u80fd\u4e0eC#\u7684\u7c7b\u5e93\u540d\u79f0\u76f8\u540c\u3002<\/li>\n<\/ol>\n
    C# \u5173\u952e\u5b57<\/strong><\/div>\n

    \u5173\u952e\u5b57\u662f C# \u7f16\u8bd1\u5668\u9884\u5b9a\u4e49\u7684\u4fdd\u7559\u5b57\u3002\u8fd9\u4e9b\u5173\u952e\u5b57\u4e0d\u80fd\u7528\u4f5c\u6807\u8bc6\u7b26\uff0c\u4f46\u662f\uff0c\u5982\u679c\u60a8\u60f3\u4f7f\u7528\u8fd9\u4e9b\u5173\u952e\u5b57\u4f5c\u4e3a\u6807\u8bc6\u7b26\uff0c\u53ef\u4ee5\u5728\u5173\u952e\u5b57\u524d\u9762\u52a0\u4e0a @ \u5b57\u7b26\u4f5c\u4e3a\u524d\u7f00\u3002<\/p>\n

    \u5728 C# \u4e2d\uff0c\u6709\u4e9b\u5173\u952e\u5b57\u5728\u4ee3\u7801\u7684\u4e0a\u4e0b\u6587\u4e2d\u6709\u7279\u6b8a\u7684\u610f\u4e49\uff0c\u5982 get \u548c set\uff0c\u8fd9\u4e9b\u88ab\u79f0\u4e3a\u4e0a\u4e0b\u6587\u5173\u952e\u5b57\uff08contextual keywords\uff09\u3002<\/p>\n

    \u4e0b\u8868\u5217\u51fa\u4e86 C# \u4e2d\u7684\u4fdd\u7559\u5173\u952e\u5b57\uff08Reserved Keywords\uff09\u548c\u4e0a\u4e0b\u6587\u5173\u952e\u5b57\uff08Contextual Keywords\uff09\uff1a<\/p>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
    \u4fdd\u7559\u5173\u952e\u5b57<\/b><\/td>\n<\/tr>\n
    abstract<\/td>\nas<\/td>\nbase<\/td>\nbool<\/td>\nbreak<\/td>\nbyte<\/td>\ncase<\/td>\n<\/tr>\n
    catch<\/td>\nchar<\/td>\nchecked<\/td>\nclass<\/td>\nconst<\/td>\ncontinue<\/td>\ndecimal<\/td>\n<\/tr>\n
    default<\/td>\ndelegate<\/td>\ndo<\/td>\ndouble<\/td>\nelse<\/td>\nenum<\/td>\nevent<\/td>\n<\/tr>\n
    explicit<\/td>\nextern<\/td>\nfalse<\/td>\nfinally<\/td>\nfixed<\/td>\nfloat<\/td>\nfor<\/td>\n<\/tr>\n
    foreach<\/td>\ngoto<\/td>\nif<\/td>\nimplicit<\/td>\nin<\/td>\nin (generic
    modifier)<\/td>\n
    int<\/td>\n<\/tr>\n
    interface<\/td>\ninternal<\/td>\nis<\/td>\nlock<\/td>\nlong<\/td>\nnamespace<\/td>\nnew<\/td>\n<\/tr>\n
    null<\/td>\nobject<\/td>\noperator<\/td>\nout<\/td>\nout
    (generic
    modifier)<\/td>\n
    override<\/td>\nparams<\/td>\n<\/tr>\n
    private<\/td>\nprotected<\/td>\npublic<\/td>\nreadonly<\/td>\nref<\/td>\nreturn<\/td>\nsbyte<\/td>\n<\/tr>\n
    sealed<\/td>\nshort<\/td>\nsizeof<\/td>\nstackalloc<\/td>\nstatic<\/td>\nstring<\/td>\nstruct<\/td>\n<\/tr>\n
    switch<\/td>\nthis<\/td>\nthrow<\/td>\ntrue<\/td>\ntry<\/td>\ntypeof<\/td>\nuint<\/td>\n<\/tr>\n
    ulong<\/td>\nunchecked<\/td>\nunsafe<\/td>\nushort<\/td>\nusing<\/td>\nvirtual<\/td>\nvoid<\/td>\n<\/tr>\n
    volatile<\/td>\nwhile<\/td>\n<\/td>\n<\/td>\n<\/td>\n<\/td>\n<\/td>\n<\/tr>\n
    \u4e0a\u4e0b\u6587\u5173\u952e\u5b57<\/b><\/td>\n<\/tr>\n
    add<\/td>\nalias<\/td>\nascending<\/td>\ndescending<\/td>\ndynamic<\/td>\nfrom<\/td>\nget<\/td>\n<\/tr>\n
    global<\/td>\ngroup<\/td>\ninto<\/td>\njoin<\/td>\nlet<\/td>\norderby<\/td>\npartial
    (type)<\/td>\n<\/tr>\n
    partial
    (method)<\/td>\n
    remove<\/td>\nselect<\/td>\nset<\/td>\n<\/td>\n<\/td>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"

    \u76f8\u540c\u79cd\u7c7b\u7684\u5bf9\u8c61\u901a\u5e38\u5177\u6709\u76f8\u540c\u7684\u7c7b\u578b\uff0c\u6216\u8005\u8bf4\uff0c\u662f\u5728\u76f8\u540c\u7684 class \u4e2d\u3002 \u4f8b\u5982\uff0c\u4ee5 Rectangle\uff08\u77e9\u5f62\uff09\u5bf9 […]<\/p>\n","protected":false},"author":321,"featured_media":232223,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-232222","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=232222"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232222\/revisions"}],"predecessor-version":[{"id":232226,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/232222\/revisions\/232226"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/232223"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=232222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=232222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=232222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}