{"id":18583,"date":"2025-07-17T09:37:51","date_gmt":"2025-07-17T01:37:51","guid":{"rendered":"https:\/\/blog.ywdevops.cn\/?p=18583"},"modified":"2025-07-17T16:37:48","modified_gmt":"2025-07-17T08:37:48","slug":"18583","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2025\/07\/17\/18583\/","title":{"rendered":"Dart\u5217\u8868"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728 Dart \u4e2d\uff0c\u6570\u7ec4\u662f&nbsp;<a href=\"https:\/\/api.dart.ac.cn\/dart-core\/List-class.html\"><code>List<\/code><\/a>&nbsp;\u5bf9\u8c61\uff0c\u56e0\u6b64\u5927\u591a\u6570\u4eba\u76f4\u63a5\u79f0\u5b83\u4eec\u4e3a<em>\u5217\u8868<\/em>\uff0cDart \u5217\u8868\u5b57\u9762\u91cf\u7531\u7528\u65b9\u62ec\u53f7 (<code>[]<\/code>) \u62ec\u8d77\u6765\u7684\u9017\u53f7\u5206\u9694\u7684\u5143\u7d20\u5217\u8868\u8868\u793a\u3002\u6bcf\u4e2a\u5143\u7d20\u901a\u5e38\u662f\u4e00\u4e2a\u8868\u8fbe\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Dart \u5217\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var list = &#91;1, 2, 3]; \/\/\u81ea\u52a8\u63a8\u65ad\u4e3aList&lt;int>\u7c7b\u578b<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Dart \u63a8\u65ad list \u7684\u7c7b\u578b\u4e3a List&lt;int>\u3002\u5982\u679c\u60a8\u5c1d\u8bd5\u5c06\u975e\u6574\u6570\u5bf9\u8c61\u6dfb\u52a0\u5230\u6b64\u5217\u8868\u4e2d\uff0c\u5206\u6790\u5668\u6216\u8fd0\u884c\u65f6\u5c06\u5f15\u53d1\u9519\u8bef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">1\u3001\u52a8\u6001\u7c7b\u578b\u5217\u8868<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528var\u81ea\u52a8\u63a8\u65ad\u7684\u5217\u8868\u4e5f\u53eb<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u52a8\u6001\u7c7b\u578b\u5217\u8868<\/mark>\uff0c\u52a8\u6001\u7c7b\u578b\u5217\u8868\u7684\u7279\u70b9\u662f\u5217\u8868\u4e2d\u5143\u7d20\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u7c7b\u578b\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var lists = &#91;1,'hello',true]; \/\/var\u58f0\u660e\uff0c\u5305\u542b\u5404\u79cd\u7c7b\u578b\n\u6216\nList lists = &#91;1,'hello',true];\/\/List\u58f0\u660e\uff0c\u5305\u542b\u5404\u79cd\u7c7b\u578b<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"141\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-11.png\" alt=\"\" class=\"wp-image-18639\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-11.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-11-300x65.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/3-11-600x130.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"82\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-11.png\" alt=\"\" class=\"wp-image-18640\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-11.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-11-300x38.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/4-11-600x76.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">2\u3001\u5f3a\u7c7b\u578b\u5217\u8868<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f3a\u7c7b\u578b\u5217\u8868\u5728\u58f0\u660e\u7684\u65f6\u5019\u8981\u6307\u5b9a\u5217\u8868\u4e2d\u5143\u7d20\u7684\u7c7b\u578b\uff0c\u56e0\u6b64\u5217\u8868\u4e2d\u5143\u7d20\u7c7b\u578b\u5355\u4e00\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var lists = &lt;int>&#91;1,2,3,4,]; \/\/\u53ea\u80fd\u662fint\n\u6216\nList&lt;int> newlists = &#91;1,2,3,4,]<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"133\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-9.png\" alt=\"\" class=\"wp-image-18642\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-9.png 659w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-9-300x61.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/5-9-600x121.png 600w\" sizes=\"auto, (max-width: 659px) 100vw, 659px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"77\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-9.png\" alt=\"\" class=\"wp-image-18643\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-9.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-9-300x36.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/6-9-600x71.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u5728 Dart \u96c6\u5408\u5b57\u9762\u91cf\u4e2d\u7684\u6700\u540e\u4e00\u9879\u540e\u6dfb\u52a0\u9017\u53f7\u3002\u8fd9\u4e2a<em>\u5c3e\u968f\u9017\u53f7<\/em>\u4e0d\u4f1a\u5f71\u54cd\u96c6\u5408\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var list = &#91;1, 2, 3,];  \/\/3\u540e\u9762\u591a\u4e86\u4e00\u4e2a\u9017\u53f7<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">3\u3001\u8bbf\u95ee\u5217\u8868<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u4f7f\u7528\u57fa\u4e8e\u96f6\u7684\u7d22\u5f15\uff0c\u5176\u4e2d 0 \u662f\u7b2c\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\uff0c<code>list.length-1<\/code>\u00a0\u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528\u00a0<code>.length<\/code>\u00a0\u5c5e\u6027\u83b7\u53d6\u5217\u8868\u7684\u957f\u5ea6\uff0c\u5e76\u4f7f\u7528\u4e0b\u6807\u8fd0\u7b97\u7b26 (<code>[]<\/code>) \u8bbf\u95ee\u5217\u8868\u7684\u5143\u7d20\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"651\" height=\"192\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-8.png\" alt=\"\" class=\"wp-image-18586\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-8.png 651w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-8-300x88.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-8-600x177.png 600w\" sizes=\"auto, (max-width: 651px) 100vw, 651px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"130\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-7.png\" alt=\"\" class=\"wp-image-18587\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-7.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-7-300x60.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-7-600x120.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7for\u5faa\u73af\u904d\u5386\u5217\u8868\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"188\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-10.png\" alt=\"\" class=\"wp-image-18646\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-10.png 650w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-10-300x87.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/7-10-600x174.png 600w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"116\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-9.png\" alt=\"\" class=\"wp-image-18647\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-9.png 652w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-9-300x53.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2025\/07\/8-9-600x107.png 600w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4\u3001\u8981\u521b\u5efa\u7f16\u8bd1\u65f6\u5e38\u91cf\u5217\u8868\uff0c\u8bf7\u5728\u5217\u8868\u5b57\u9762\u91cf\u524d\u6dfb\u52a0\u00a0<code>const<\/code>\uff0c\u6b64\u65f6\u5217\u8868\u4e0d\u53ef\u4fee\u6539\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var Lists = const &lt;int>&#91;1, 2, 3];\n\/\/Lists&#91;2] = 10; \u5c06\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u4e0d\u53ef\u4fee\u6539\uff0c\u4f46\u662fLists\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c\nLists = &#91;5,6,7,8];  \/\/\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u8981\u521b\u5efa\u4e0d\u53ef\u91cd\u65b0\u8d4b\u503c\u7684\u5217\u8868\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528final\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>final Lists = const &lt;int>&#91;1,2,3];\nLists = &#91;5,6,7];  \/\/\u62a5\u9519\uff0c\u4e0d\u53ef\u4ee5\u91cd\u65b0\u8d4b\u503c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f7f\u7528final\u58f0\u660e\u53d8\u91cf\u4f46\u662f\u96c6\u5408\u6ca1\u6709\u4f7f\u7528const\uff0c\u90a3\u4e48Lists\u4e0d\u80fd\u91cd\u65b0\u8d4b\u503c\u4f46\u662f\u53ef\u4ee5\u4fee\u6539\u5b83\u7684\u503c\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>final Lists = &lt;int>&#91;1,2,3];\/\/\u6ca1\u6709\u4f7f\u7528const\nLists&#91;1] = 8;   \/\/\u5217\u8868\u53d8\u4e3a&#91;1,8,3]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">5\u3001\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u662f\u4e0d\u662f\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528if\u5faa\u73af\uff0c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var lists = &lt;int>&#91;1, 2, 3, 4]; \/\/\u5f3a\u7c7b\u578b\uff0c\u53ea\u80fd\u662fint\n  \/\/\u5224\u65ad\u662f\u5426\u4e3aList\n  if (lists is List) {\n    print('yes');\n  } else {\n    print('no');\n  }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Dart \u4e2d\uff0c\u6570\u7ec4\u662f&nbsp;List&nbsp;\u5bf9\u8c61\uff0c\u56e0\u6b64\u5927\u591a\u6570\u4eba\u76f4\u63a5\u79f0\u5b83\u4eec\u4e3a\u5217\u8868\uff0cDart \u5217\u8868\u5b57\u9762 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":18605,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[158],"tags":[],"class_list":["post-18583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dart"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=18583"}],"version-history":[{"count":18,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18583\/revisions"}],"predecessor-version":[{"id":18649,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/18583\/revisions\/18649"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/18605"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=18583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=18583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=18583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}