{"id":805,"date":"2021-09-08T21:24:51","date_gmt":"2021-09-08T13:24:51","guid":{"rendered":"http:\/\/www.wayln.com\/?p=805"},"modified":"2021-09-09T14:55:36","modified_gmt":"2021-09-09T06:55:36","slug":"%e5%bc%82%e6%ad%a5%e6%b5%81","status":"publish","type":"post","link":"https:\/\/www.wayln.com\/?p=805","title":{"rendered":"\u5f02\u6b65\u6d41"},"content":{"rendered":"<div id=\"toc_container\" class=\"toc_transparent no_bullets\"><p class=\"toc_title\">Contents<\/p><ul class=\"toc_list\"><li><a href=\"#TaskltT62\"><span class=\"toc_number toc_depth_1\">1<\/span> \u5f02\u6b65\u6d41\u548cTask&lt;T&#62;<\/a><\/li><li><a href=\"#IEnumerableltT62\"><span class=\"toc_number toc_depth_1\">2<\/span> \u5f02\u6b65\u6d41\u548cIEnumerable&lt;T&#62;<\/a><\/li><li><a href=\"#IObservable\"><span class=\"toc_number toc_depth_1\">3<\/span> \u5f02\u6b65\u6d41\u548cIObservable<\/a><\/li><li><a href=\"#i\"><span class=\"toc_number toc_depth_1\">4<\/span> \u521b\u5efa\u5f02\u6b65\u6d41<\/a><\/li><\/ul><\/div>\n<p>\u5f02\u6b65\u6d41\uff08asynchronous stream)\u662f\u4e00\u79cd\u5f02\u6b65\u63a5\u6536\u591a\u4e2a\u6570\u636e\u9879\u7684\u65b9\u5f0f\uff0c\u5176\u5efa\u7acb\u5728\u5f02\u6b65\u679a\u4e3e\u4e4b\u4e0a\uff08IAsyncEnumerable&lt;T&#62;)\u3002\u5f02\u6b65\u679a\u4e3e\u662f\u4e00\u79cd\u5f02\u6b65\u7248\u672c\u7684\u679a\u4e3e\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4ed6\u53ef\u4ee5\u4f9d\u7167\u4f7f\u7528\u8005\u7684\u8981\u6c42\u5f02\u6b65\u751f\u6210\u6570\u636e\u9879\u3002<\/p>\n<h1><span id=\"TaskltT62\">\u5f02\u6b65\u6d41\u548cTask&lt;T&#62;<\/span><\/h1>\n<p>Task&lt;T&#62;\u7684\u6807\u51c6\u5f02\u6b65\u65b9\u6cd5\u53ea\u8db3\u4ee5\u5e94\u5bf9\u5f02\u6b65\u5904\u7406\u5355\u4e2a\u6570\u636e\u503c\uff0c\u4e00\u65e6\u67d0\u4e2aTask&lt;T&#62;\u5b8c\u6210\uff0c\u4efb\u52a1\u5c31\u7ed3\u675f\u4e86\uff0c\u5355\u4e2aTask&lt;T&#62;\u4e0d\u80fd\u4e3a\u5176\u4f7f\u7528\u8005\u63d0\u4f9b\u591a\u4e2aT\u503c\u3002\u5373\u4f7fT\u662f\u4e00\u4e2a\u96c6\u5408\uff0c\u8be5\u503c\u4e5f\u53ea\u80fd\u63d0\u4f9b\u4e00\u6b21\u3002<br \/>\n\u4e0eTask&lt;T&#62;\u76f8\u6bd4\uff0c\u5f02\u6b65\u6d41\u66f4\u7c7b\u4f3c\u4e8e\u679a\u4e3e\uff0c\u5177\u4f53\u6765\u8bf4\uff0cIAsyncEnumerator&lt;T&#62;\u53ef\u4ee5\u63d0\u4f9b\u4efb\u610f\u6570\u91cf\u7684T\u503c\uff0c\u800c\u4e14\u4e00\u6b21\u4e00\u4e2a\uff0c\u548cIEnumerator&lt;T&#62;\u4e00\u6837\uff0cIAsyncEnumerator&lt;T&#62;\u53ef\u4ee5\u662f\u65e0\u73b0\u573a\u7684<\/p>\n<h1><span id=\"IEnumerableltT62\">\u5f02\u6b65\u6d41\u548cIEnumerable&lt;T&#62;<\/span><\/h1>\n<p>IEnumerable&lt;T&#62;\u90fd\u4f1a\u963b\u585e\u4ee3\u7801\uff0cIAsyEnumerable&lt;T&#62;\u4f1a\u5f02\u6b65\u83b7\u53d6\u4e0b\u4e00\u4e2a\u5143\u7d20\u3002<br \/>\n#\u5f02\u6b65\u6d41\u548cTask&lt;IEnumerable&lt;T&#62;><br \/>\n\u5f02\u6b65\u8fd4\u56de\u7684\u96c6\u5408\u5b8c\u5168\u53ef\u4ee5\u5305\u542b\u591a\u4e2a\u6570\u636e\u9879\uff0cTask&lt;List<T\/>>\u3002\u8fd4\u56deList<T\/>\u7684async\u65b9\u6cd5\u4ecd\u65e7\u53ea\u6709\u4e00\u6761return\u8bed\u53e5\uff0c\u5728\u5c06\u96c6\u5408\u8fd4\u56de\u4e4b\u524d\u5fc5\u987b\u5c06\u5176\u5f7b\u5e95\u586b\u5145\u3002\u5373\u4f7f\u662f\u8fd4\u56deTask&lt;IEnumerable<T\/>>\u7684\u65b9\u6cd5\uff0c\u4e5f\u80fd\u591f\u5f02\u6b65\u8fd4\u56de\u679a\u4e3e\uff0c\u4f46\u968f\u540e\u8be5\u679a\u4e3e\u5c06\u88ab\u540c\u6b65\u8ba1\u7b97\u3002\u6ce8\u610fLINQ to Entities\u4e2d\u6709\u4e00\u4e2aToListAsync LINQ\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56deTask&lt;List&lt;T&#62;>\u3002\u5f53LINQ\u63d0\u4f9b\u7a0b\u5e8f\u6267\u884c\u6b64\u64cd\u4f5c\u65f6\uff0c\u5b83\u5fc5\u987b\u4e0e\u6570\u636e\u5e93\u901a\u4fe1\uff0c\u5e76\u5728\u5b8c\u6210\u586b\u5145\u5217\u8868\u548c\u8fd4\u56de\u5b83\u4e4b\u524d\u83b7\u53d6\u6240\u6709\u5339\u914d\u7684\u54cd\u5e94\u3002<br \/>\nTask&lt;IEnumerable&lt;T&#62;>\u7684\u5c40\u9650\u5728\u4e8e\u65e0\u6cd5\u8fd4\u56de\u521a\u83b7\u53d6\u7684\u6570\u636e\u9879\u3002\u5982\u679c\u8fd4\u56de\u96c6\u5408\uff0c\u90a3\u4e48\u5b83\u5fc5\u987b\u628a\u6240\u6709\u76f8\u90fd\u52a0\u5728\u5230\u5185\u5b58\u4e2d\uff0c\u586b\u5145\u8be5\u96c6\u5408\uff0c\u7136\u540e\u4e00\u6b21\u6027\u8fd4\u56de\u6574\u4e2a\u96c6\u5408\u3002\u5373\u4fbf\u5b83\u8fd4\u56deLINQ\u67e5\u8be2\uff0c\u5e76\u4e14\u53ef\u4ee5\u5f02\u6b65\u6784\u5efa\u8be5\u67e5\u8be2\uff0c\u4f46\u4e00\u7ecf\u8fd4\u56de\uff0c\u8be5\u67e5\u8be2\u4e2d\u7684\u6bcf\u4e00\u9879\u4e5f\u662f\u540c\u6b65\u83b7\u53d6\u7684\u3002IAsyncEnumerable&lt;T&#62;\u4e5f\u4f1a\u5f02\u6b65\u8fd4\u56de\u591a\u4e2a\u6570\u636e\u9879\uff0c\u4f46\u533a\u522b\u5728\u4e8e\uff0cIAsyncEnumerable&lt;T&#62;\u53ef\u4ee5\u9488\u5bf9\u8fd4\u56de\u7684\u6bcf\u4e00\u9879\u6267\u884c\u5f02\u6b65\u64cd\u4f5c\uff0c\u8fd9\u662f\u771f\u6b63\u7531\u6570\u636e\u9879\u7ec4\u6210\u7684\u5f02\u6b65\u6d41\u3002<\/p>\n<h1><span id=\"IObservable\">\u5f02\u6b65\u6d41\u548cIObservable<T\/><\/span><\/h1>\n<p>\u53ef\u89c2\u5bdf\u5bf9\u8c61\u662f\u771f\u6b63\u7684\u5f02\u6b65\u6d41\u6982\u5ff5\uff0c\u5b83\u4e00\u6b21\u751f\u6210\u591a\u4e2a\u901a\u77e5\uff0c\u771f\u6b63\u652f\u6301\u5f02\u6b65\u751f\u4ea7\uff08\u65e0\u963b\u585e\uff09\u3002\u4e0d\u8fc7IObservable&lt;T&#62;\u7684\u6d88\u8017\u65b9\u5f0f\u4e0eIAsyncEnumerable&lt;T&#62;\u622a\u7136\u4e0d\u540c\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u5355\u503c\/\u591a\u503c<\/th>\n<th>\u5f02\u6b65\/\u540c\u6b65<\/th>\n<th>\u63a8\u62c9\/\u62c9\u5f0f<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>T<\/td>\n<td>\u5355\u503c<\/td>\n<td>\u540c\u6b65<\/td>\n<td>\u90fd\u4e0d\u662f<\/td>\n<\/tr>\n<tr>\n<td>IEnumerable&lt;T&#62;<\/td>\n<td>\u591a\u503c<\/td>\n<td>\u540c\u6b65<\/td>\n<td>\u90fd\u4e0d\u662f<\/td>\n<\/tr>\n<tr>\n<td>Task&lt;T&#62;<\/td>\n<td>\u5355\u503c<\/td>\n<td>\u5f02\u6b65<\/td>\n<td>\u62c9\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>IAsyncEnumerable&lt;T&#62;<\/td>\n<td>\u591a\u503c<\/td>\n<td>\u5f02\u6b65<\/td>\n<td>\u62c9\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>IObservable&lt;T&#62;<\/td>\n<td>\u5355\u503c\u6216\u591a\u503c<\/td>\n<td>\u5f02\u6b65<\/td>\n<td>\u63a8\u5f0f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1><span id=\"i\">\u521b\u5efa\u5f02\u6b65\u6d41<\/span><\/h1>\n<p>\u5047\u8bbe\u9700\u8981\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u800c\u4e14\u9700\u8981\u5bf9\u6bcf\u4e2a\u503c\u6267\u884c\u4e00\u4e9b\u5f02\u6b65\u5904\u7406\uff0c\u4e0b\u9762\u7684\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e2a\u64cd\u4f5c<br \/>\n&#8211; \u901a\u8fc7IEnumerable&lt;T&#62; \u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u7136\u540e\u5bf9\u5176\u8fdb\u884c\u5f02\u6b65\u5904\u7406\u3002<br \/>\n&#8211; \u901a\u8fc7Task&lt;T&#62;\u5f02\u6b65\u8fd4\u56de\u5355\u4e2a\u503c\uff0c\u7136\u540e\u6dfb\u52a0\u5176\u4ed6\u7684\u8fd4\u56de\u503c<br \/>\n\u901a\u8fc7yield return \u53ef\u4ee5\u4ece\u4e00\u4e2a\u65b9\u6cd5\u8fd4\u56de\u591a\u4e2a\u503c\uff0c\u800c\u5f02\u6b65\u65b9\u6cd5\u4f7f\u7528async\u548cawait\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Contents1 \u5f02\u6b65\u6d41\u548cTask&lt;T&#62;2 \u5f02\u6b65\u6d41\u548cIEnumerable&lt;T&#62; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,41,2],"tags":[],"class_list":["post-805","post","type-post","status-publish","format-standard","hentry","category-c","category-41","category-2"],"_links":{"self":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=805"}],"version-history":[{"count":3,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/805\/revisions"}],"predecessor-version":[{"id":809,"href":"https:\/\/www.wayln.com\/index.php?rest_route=\/wp\/v2\/posts\/805\/revisions\/809"}],"wp:attachment":[{"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wayln.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}