{"id":216798,"date":"2021-04-30T10:17:03","date_gmt":"2021-04-30T02:17:03","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=216798"},"modified":"2021-04-25T09:18:52","modified_gmt":"2021-04-25T01:18:52","slug":"variable-initialization-analysis","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/variable-initialization-analysis.html","title":{"rendered":"C# \u53d8\u91cf\u521d\u59cb\u5316\u89e3\u6790"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nC# \u53d8\u91cf\u521d\u59cb\u5316\u662f C# \u5f3a\u8c03\u5b89\u5168\u6027\u7684\u53e6\u4e00\u4e2a\u4f8b\u5b50\u3002\u7b80\u5355\u5730\u8bf4\uff0cC# \u7f16\u8bd1\u5668\u9700\u8981\u7528\u67d0\u4e2a\u521d\u59cb\u503c\u5bf9\u53d8\u91cf\u8fdb\u884c\u521d\u59cb\u5316\uff0c\u4e4b\u540e\u624d\u80fd\u5728\u64cd\u4f5c\u4e2d\u5f15\u7528\u8be5\u53d8\u91cf\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5927\u591a\u6570\u73b0\u4ee3\u7f16\u8bd1\u5668\u628a\u6ca1\u6709\u521d\u59cb\u5316\u6807\u8bb0\u4e3a\u8b66\u544a\uff0c\u4f46C#\u7f16\u8bd1\u5668\u628a\u5b83\u5f53\u4f5c\u9519\u8bef\u6765\u770b\u5f85\u3002\u8fd9\u5c31\u53ef\u4ee5\u9632\u6b62\u6211\u4eec\u65e0\u610f\u4e2d\u4ece\u5176\u4ed6\u7a0b\u5e8f\u9057\u7559\u4e0b\u6765\u7684\u5185\u5b58\u4e2d\u83b7\u53d6\u5783\u573e\u503c\u3002<\/p>\n

C# \u53d8\u91cf\u521d\u59cb\u5316\u7684\u64cd\u4f5c\u4e2d\u6709\u4e24\u4e2a\u65b9\u6cd5\u53ef\u786e\u4fdd\u53d8\u91cf\u5728\u4f7f\u7528\u524d\u8fdb\u884c\u4e86\u521d\u59cb\u5316\uff1a<\/p>\n

    \n
  1. \u53d8\u91cf\u662f\u7c7b\u6216\u7ed3\u6784\u4e2d\u7684\u5b57\u6bb5\uff0c\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u521d\u59cb\u5316\uff0c\u521b\u5efa\u8fd9\u4e9b\u53d8\u91cf\u65f6\uff0c\u5176\u503c\u5c31\u9ed8\u8ba4\u662f 0(\u7c7b\u548c\u7ed3\u6784\u5728\u540e\u9762\u8ba8\u8bba)\u3002<\/li>\n
  2. \u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\u5fc5\u987b\u5728\u4ee3\u7801\u4e2d\u663e\u5f0f\u521d\u59cb\u5316\uff0c\u4e4b\u540e\u624d\u80fd\u5728\u8bed\u53e5\u4e2d\u4f7f\u7528\u5b83\u4eec\u7684\u503c\u3002\u6b64\u65f6\uff0c\u521d\u59cb\u5316\u4e0d\u662f\u5728\u58f0\u660e\u8be5\u53d8\u91cf\u65f6\u8fdb\u884c\u7684\uff0c\u4f46\u7f16\u8bd1\u5668\u4f1a\u901a\u8fc7\u65b9\u6cd5\u68c0\u67e5\u6240\u6709\u53ef\u80fd\u7684\u8def\u5f84\uff0c\u5982\u679c\u68c0\u6d4b\u5230\u5c40\u90e8\u53d8\u91cf\u5728\u521d\u59cb\u5316\u4e4b\u524d\u5c31\u4f7f\u7528\u4e86\u5b83\u7684\u503c\uff0c\u5c31\u4f1a\u4ea7\u751f\u9519\u8bef\u3002<\/li>\n<\/ol>\n

    C# \u7684\u65b9\u6cd5\u4e0e C++ \u7684\u65b9\u6cd5\u76f8\u53cd\uff0c\u5728 C++ \u4e2d\uff0c\u7f16\u8bd1\u5668\u8ba9\u7a0b\u5e8f\u5458\u786e\u4fdd\u53d8\u91cf\u5728\u4f7f\u7528\u4e4b\u524d\u8fdb\u884c\u4e86\u521d\u59cb\u5316\uff0c\u5728 Visual Basic \u4e2d\uff0c\u6240\u6709\u7684\u53d8\u91cf\u90fd\u4f1a\u81ea\u52a8\u628a\u5176\u503c\u8bbe\u7f6e\u4e3a 0\u3002<\/p>\n

    C# \u53d8\u91cf\u521d\u59cb\u5316\u5b9e\u4f8b\u89e3\u6790<\/strong><\/div>\n

    \u4f8b\u5982\uff0c\u5728C # \u4e2d\u4e0d\u80fd\u4f7f\u7528\u4e0b\u9762\u7684\u8bed\u53e5\uff1a<\/p>\n

    public static int Main(){ int d; Console.WriteLine(d); \/\/ \u62a5\u9519! \u4f7f\u7528\u4e4b\u524d\u5fc5\u987b\u521d\u59cb\u5316 }
    \n\u6ce8\u610f\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u5b9a\u4e49 Main()\uff0c\u4f7f\u4e4b\u8fd4\u56de\u4e00\u4e2a int \u7c7b\u578b\u7684\u6570\u636e\uff0c\u800c\u4e0d \u662fvoid\u3002<\/p>\n

    \u5728\u7f16\u8bd1\u8fd9\u4e9b\u4ee3\u7801\u65f6\uff0c\u4f1a\u5f97\u5230\u4e0b\u9762\u7684\u9519\u8bef\u6d88\u606f\uff1a<\/p>\n

    Use of unassigned local variable 'd' <\/pre>\n

    \u8003\u8651\u4e0b\u9762\u7684\u8bed\u53e5\uff1a<\/p>\n

    Something objSomething;<\/pre>\n

    \u5728 C++ \u4e2d\uff0c\u4e0a\u9762\u7684\u4ee3\u7801\u4f1a\u5728\u5806\u6808\u4e2d\u521b\u5efa Something \u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u5728 C# \u4e2d\uff0c\u8fd9\u884c\u4ee3\u7801\u4ec5\u4f1a\u4e3a Something \u5bf9\u8c61\u521b\u5efa\u4e00\u4e2a\u5f15\u7528\uff0c\u4f46\u8fd9\u4e2a\u5f15\u7528\u8fd8\u6ca1\u6709\u6307\u5411\u4efb\u4f55\u5bf9\u8c61\u3002\u5bf9\u8be5\u53d8\u91cf\u8c03\u7528\u65b9\u6cd5\u6216\u5c5e\u6027\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/p>\n

    \u5728 C# \u4e2d\u5b9e\u4f8b\u5316\u4e00\u4e2a\u5f15\u7528\u5bf9\u8c61\u9700\u8981\u4f7f\u7528 new \u5173\u952e\u5b57\u3002\u5982\u4e0a\u6240\u8ff0\uff0c\u521b\u5efa\u4e00\u4e2a\u5f15\u7528\uff0c\u4f7f\u7528 new \u5173\u952e\u5b57\u628a\u8be5\u5f15\u7528\u6307\u5411\u5b58\u50a8\u5728\u5806\u4e0a\u7684\u4e00\u4e2a\u5bf9\u8c61\uff1a<\/p>\n

    objSomething = new Something();<\/pre>\n","protected":false},"excerpt":{"rendered":"

    \u5927\u591a\u6570\u73b0\u4ee3\u7f16\u8bd1\u5668\u628a\u6ca1\u6709\u521d\u59cb\u5316\u6807\u8bb0\u4e3a\u8b66\u544a\uff0c\u4f46C#\u7f16\u8bd1\u5668\u628a\u5b83\u5f53\u4f5c\u9519\u8bef\u6765\u770b\u5f85\u3002\u8fd9\u5c31\u53ef\u4ee5\u9632\u6b62\u6211\u4eec\u65e0\u610f\u4e2d\u4ece\u5176\u4ed6\u7a0b\u5e8f\u9057\u7559\u4e0b […]<\/p>\n","protected":false},"author":1481,"featured_media":216802,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-216798","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\/216798","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\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=216798"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216798\/revisions"}],"predecessor-version":[{"id":216807,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/216798\/revisions\/216807"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/216802"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=216798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=216798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=216798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}