{"id":1435,"date":"2023-05-20T10:43:31","date_gmt":"2023-05-20T02:43:31","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1435"},"modified":"2023-05-20T10:43:31","modified_gmt":"2023-05-20T02:43:31","slug":"c8-10%e7%89%88%e6%9c%ac%e4%b8%ad%e7%9a%84%e6%96%b0%e8%af%ad%e6%b3%95%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2023\/05\/20\/c8-10%e7%89%88%e6%9c%ac%e4%b8%ad%e7%9a%84%e6%96%b0%e8%af%ad%e6%b3%95%e7%a4%ba%e4%be%8b\/","title":{"rendered":"C#8-10\u7248\u672c\u4e2d\u7684\u65b0\u8bed\u6cd5\u793a\u4f8b"},"content":{"rendered":"\n<p>2.1.1 \u9876\u7ea7\u8bed\u53e5<\/p>\n\n\n\n<p>\u5728\u4ee5\u524d\u7248\u672c\u7684C#\u8bed\u6cd5\u4e2d\uff0c\u5373\u4f7f\u53ea\u7f16\u5199\u4e00\u884c\u8f93\u51fa\u201cHello world\u201d\u7684C#\u4ee3\u7801\uff0c\u4e5f\u9700\u8981\u521b\u5efa\u4e00\u4e2aC#\u7c7b\uff0c\u5e76\u4e14\u9700\u8981\u4e3a\u8fd9\u4e2aC#\u7c7b\u6dfb\u52a0Main\u65b9\u6cd5\uff0c\u624d\u80fd\u5728Main\u65b9\u6cd5\u4e2d\u7f16\u5199\u4ee3\u7801\u3002\u4eceC# 9.0\u5f00\u59cb\uff0cC#\u589e\u52a0\u4e86\u201c\u9876\u7ea7\u8bed\u53e5\u201d\u8bed\u6cd5\uff0c\u5b83\u4f7f\u5f97\u53ef\u4ee5\u76f4\u63a5\u5728C#\u6587\u4ef6\u4e2d\u7f16\u5199\u5165\u53e3\u4ee3\u7801\uff0c\u4e0d\u518d\u9700\u8981\u58f0\u660e\u7c7b\u548c\u65b9\u6cd5<\/p>\n\n\n\n<p>2.1.2 \u5168\u5c40using\u6307\u4ee4<\/p>\n\n\n\n<p>\u5728\u7f16\u5199\u9879\u76ee\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u6211\u4eec\u7ecf\u5e38\u9700\u8981\u5f15\u7528\u975e\u5e38\u591a\u7684.NET\u5b98\u65b9\u53ca\u7b2c\u4e09\u65b9\u7684\u7c7b\u5e93\uff0c\u800c\u8fd9\u4e9b\u7c7b\u5e93\u901a\u5e38\u4f4d\u4e8e\u4e0d\u540c\u7684\u547d\u540d\u7a7a\u95f4\u4e0b\uff0c\u8fd9\u6837\u5c31\u9700\u8981\u5728\u6bcf\u4e2aC#\u6587\u4ef6\u5934\u90e8\u7f16\u5199\u91cd\u590d\u7684using\u8bed\u53e5\u6765\u5f15\u5165\u8fd9\u4e9b\u547d\u540d\u7a7a\u95f4\uff0c\u975e\u5e38\u70e6\u7410\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/sanlangcode.com\/wp-content\/uploads\/2023\/05\/image-3.png\" alt=\"\" class=\"wp-image-1437\"\/><\/figure>\n\n\n\n<p>C# 10.0\u4e2d\u589e\u52a0\u4e86\u201c\u5168\u5c40using\u6307\u4ee4\u201d\u8bed\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06global\u4fee\u9970\u7b26\u6dfb\u52a0\u5230\u4efb\u4f55using\u5173\u952e\u5b57\u524d\uff0c\u8fd9\u6837\u901a\u8fc7using\u8bed\u53e5\u5f15\u5165\u7684\u547d\u540d\u7a7a\u95f4\u5c31\u53ef\u4ee5\u5e94\u7528\u5230\u8fd9\u4e2a\u9879\u76ee\u7684\u6240\u6709\u6e90\u4ee3\u7801\u4e2d\uff0c\u56e0\u6b64\u540c\u4e00\u4e2a\u9879\u76ee\u4e2d\u7684C#\u4ee3\u7801\u5c31\u4e0d\u9700\u8981\u518d\u53bb\u91cd\u590d\u5f15\u5165\u8fd9\u4e2a\u547d\u540d\u7a7a\u95f4\u4e86\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u901a\u5e38\u521b\u5efa\u4e00\u4e2a\u4e13\u95e8\u7528\u6765\u7f16\u5199\u5168\u5c40using\u4ee3\u7801\u7684C#\u6587\u4ef6\uff0c\u7136\u540e\u628a\u6240\u6709\u5728\u9879\u76ee\u4e2d\u7ecf\u5e38\u7528\u5230\u7684\u547d\u540d\u7a7a\u95f4\u58f0\u660e\u5230\u8fd9\u4e2aC#\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p>2.1.3 using\u58f0\u660e<\/p>\n\n\n\n<p>C#\u4e2d\u53ef\u4ee5\u7528using\u5173\u952e\u5b57\u6765\u7b80\u5316\u975e\u6258\u7ba1\u8d44\u6e90\u7684\u91ca\u653e\uff0c\u5f53\u53d8\u91cf\u79bb\u5f00using\u4f5c\u7528\u7684\u8303\u56f4\u540e\uff0c\u4f1a\u81ea\u52a8\u8c03\u7528\u5bf9\u8c61\u7684Dispose\u65b9\u6cd5\uff0c\u4ece\u800c\u5b8c\u6210\u975e\u6258\u7ba1\u8d44\u6e90\u7684\u91ca\u653e\u3002\u4f46\u662f\uff0c\u5982\u679c\u4e00\u6bb5\u4ee3\u7801\u4e2d\u6709\u5f88\u591a\u975e\u6258\u7ba1\u8d44\u6e90\u9700\u8981\u88ab\u91ca\u653e\uff0c\u4ee3\u7801\u4e2d\u5c31\u4f1a\u5b58\u5728\u591a\u4e2a\u5d4c\u5957\u7684using\u8bed\u53e5\u3002<\/p>\n\n\n\n<p>\u4ee3\u7801\u4e2d\u5b58\u5728\u591a\u5c42using\u4f5c\u7528\u57df\u7684\u5d4c\u5957\uff0c\u56e0\u6b64\u4ee3\u7801\u7ed3\u6784\u6bd4\u8f83\u590d\u6742\u3002\u5728C# 8.0\u53ca\u4e4b\u540e\u7684\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b80\u5316\u7684\u201cusing\u58f0\u660e\u201d\u8bed\u6cd5\u6765\u907f\u514d\u4ee3\u7801\u7684\u5d4c\u5957\uff0c\u5982\u4ee3\u78012-6\u6240\u793a\u3002\u5728\u58f0\u660e\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u5982\u679c\u7c7b\u578b\u5b9e\u73b0\u4e86IDisposable\u6216IAsyncDisposable\u63a5\u53e3\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u53d8\u91cf\u58f0\u660e\u524d\u52a0\u4e0ausing\u5173\u952e\u5b57\uff0c\u8fd9\u6837\u5f53\u4ee3\u7801\u6267\u884c\u79bb\u5f00\u88abusing\u4fee\u9970\u7684\u53d8\u91cf\u4f5c\u7528\u57df\u7684\u65f6\u5019\uff0c\u53d8\u91cf\u6307\u5411\u7684\u5bf9\u8c61\u7684Dispose\u65b9\u6cd5\u5c31\u4f1a\u88ab\u8c03\u7528\u3002<\/p>\n\n\n\n<p>\u4ee3\u78012-5\u4e2d\u5b58\u5728\u591a\u5c42using\u4f5c\u7528\u57df\u7684\u5d4c\u5957\uff0c\u56e0\u6b64\u4ee3\u7801\u7ed3\u6784\u6bd4\u8f83\u590d\u6742\u3002\u5728C# 8.0\u53ca\u4e4b\u540e\u7684\u7248\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u7b80\u5316\u7684\u201cusing\u58f0\u660e\u201d\u8bed\u6cd5\u6765\u907f\u514d\u4ee3\u7801\u7684\u5d4c\u5957\uff0c\u5982\u4ee3\u78012-6\u6240\u793a\u3002\u5728\u58f0\u660e\u53d8\u91cf\u7684\u65f6\u5019\uff0c\u5982\u679c\u7c7b\u578b\u5b9e\u73b0\u4e86IDisposable\u6216IAsyncDisposable\u63a5\u53e3\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u53d8\u91cf\u58f0\u660e\u524d\u52a0\u4e0ausing\u5173\u952e\u5b57\uff0c\u8fd9\u6837\u5f53\u4ee3\u7801\u6267\u884c\u79bb\u5f00\u88abusing\u4fee\u9970\u7684\u53d8\u91cf\u4f5c\u7528\u57df\u7684\u65f6\u5019\uff0c\u53d8\u91cf\u6307\u5411\u7684\u5bf9\u8c61\u7684Dispose\u65b9\u6cd5\u5c31\u4f1a\u88ab\u8c03\u7528\u3002<\/p>\n\n\n\n<p>2.1.4 \u6587\u4ef6\u8303\u56f4\u7684\u547d\u540d\u7a7a\u95f4\u58f0\u660e<\/p>\n\n\n\n<p>2.1.5 \u53ef\u4e3a\u7a7a\u7684\u5f15\u7528\u7c7b\u578b<\/p>\n\n\n\n<p>2.1.6 \u8bb0\u5f55\u7c7b\u578b<\/p>\n\n\n\n<p>C#\u8fd8\u6709\u5f88\u591a\u4f18\u79c0\u7684\u65b0\u589e\u8bed\u6cd5\uff0c\u6bd4\u5982\u5143\u7ec4\u3001\u89e3\u6784\u3001\u672c\u5730\u65b9\u6cd5\u3001\u6a21\u5f0f\u5339\u914d\u3001\u9ed8\u8ba4\u63a5\u53e3\u65b9\u6cd5\u3001\u7d22\u5f15\u548c\u8303\u56f4\u3001<strong>null\u5408\u5e76\u8d4b\u503c<\/strong>\u3001\u5206\u90e8\u65b9\u6cd5\u3001<strong>\u6e90\u4ee3\u7801\u751f\u6210\u5668<\/strong>\u7b49\uff0c\u8bfb\u8005\u53ef\u4ee5\u53c2\u8003<strong>\u5fae\u8f6f\u7684\u5b98\u65b9\u6587\u6863<\/strong>\u4e86\u89e3\u8fd9\u4e9b\u8bed\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2.1.1 \u9876\u7ea7\u8bed\u53e5 \u5728\u4ee5\u524d\u7248\u672c&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1435","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1435"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1435\/revisions"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}