{"id":2042,"date":"2024-05-07T12:53:40","date_gmt":"2024-05-07T04:53:40","guid":{"rendered":"https:\/\/wp.minicoda.com\/?p=2042"},"modified":"2025-03-19T13:16:24","modified_gmt":"2025-03-19T05:16:24","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9c%89%e5%8f%af%e7%a9%ba%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/wp.minicoda.com\/index.php\/%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9c%89%e5%8f%af%e7%a9%ba%e7%b1%bb%e5%9e%8b\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u6709\u201c\u53ef\u7a7a\u7c7b\u578b\u201c?"},"content":{"rendered":"\n<p>  \u7f16\u7a0b\u4e2d\u4f1a\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u7528\u6574\u578b\u6b63\u6570\u4ee3\u8868\u6570\u636e\u7684\u503c\uff0c-1\u4ee3\u8868\u9519\u8bef\u3002\u7a0b\u5e8f\u5458\u5fc5\u987b\u5206\u6e05\u695a\u8fd9\u4e24\u79cd\u60c5\u51b5\uff0c\u907f\u514d\u5c06-1\u5f53\u505a\u662f\u6570\u636e\u6709\u6548\u503c\u3002\u53ef\u7a7a\u7c7b\u578b\u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Swift\u652f\u6301\u53ef\u7a7a\u7c7b\u578b(\u7c7b\u578b\u540e\u9762\u591a\u4e00\u4e2a\u201c?\u201d)\uff0c\u89e3\u51b3\u4e0a\u9762\u7684\u95ee\u9898\u3002<br>var a: Int?<br><br>if let b = a {<br>&nbsp; &nbsp; print(\"Has value\")       <em><strong>\/\/ a\u6709\u8d4b\u503c<\/strong><\/em><br>} else {<br>&nbsp; &nbsp; print(\"Has no value\")  <em><strong>\/\/ a\u6ca1\u6709\u88ab\u8d4b\u503c<\/strong><\/em><br>}<\/li>\n\n\n\n<li>C\/ObjC\/C++\u8bed\u6cd5\u90fd\u6ca1\u6709\"\u53ef\u7a7a\u7c7b\u578b\"\u3002<\/li>\n\n\n\n<li>C#\u7684\u53ef\u7a7a\u7c7b\u578b\u662f\"<code>nullable<\/code>\"\u7c7b\u578b\uff0c\u53ef\u8868\u793a\u4e00\u4e2a\u503c\u53ef\u80fd\u4e3a\u7a7a\u7684\u60c5\u51b5\u3002\n<ul class=\"wp-block-list\">\n<li>C# 2.0\u5f00\u59cb\u652f\u6301\u57fa\u672c\u7c7b\u578b\u7684\u53ef\u7a7a\u7c7b\u578b\uff0cC# 8.0\u652f\u6301\u5f15\u7528\u7c7b\u578b\u53ef\u7a7a\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Java\u5229\u7528\u6cdb\u578bOptional\u652f\u6301\u53ef\u7a7a\u7c7b\u578b\u3002<\/li>\n\n\n\n<li>Kotlin \u4e5f\u5728\u7c7b\u578b\u540e\u52a0\u989d\u5916\u7684?\u8868\u793a\u53ef\u7a7a\u7c7b\u578b\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f00\u542f\u53ef\u7a7a\u7c7b\u578b<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C#\u53ef\u4ee5\u7528\u5982\u4e0b\u4e09\u79cd\u65b9\u5f0f\u5f00\u542f\u53ef\u7a7a\u7c7b\u578b\uff1a\n<ul class=\"wp-block-list\">\n<li>\u4ee3\u7801\uff1a#nullable enable  (\u4ee3\u7801\u6240\u5728\u8303\u56f4)<\/li>\n\n\n\n<li>\u5de5\u7a0b\u6587\u4ef6\uff1a&lt;Nullable&gt;enable&lt;\/Nullable&gt;  \uff08\u5168\u5c40\u8303\u56f4\uff09<\/li>\n\n\n\n<li>dotnet\u7f16\u8bd1\u9009\u9879: dotnet build \/p:Nullable=enable<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">null\u503c\u6761\u4ef6\u8fd0\u7b97\u7b26<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C# 6.0\u5f15\u5165\u4e86\u6b64\u8fd0\u7b97\u7b26\uff0c\u907f\u514d\u6bcf\u6b21\u5224\u65ad\u4e00\u4e2a\u5f15\u7528\u662f\u5426\u662fnull\u518d\u505a\u89e3\u5f15\u7528\u3002<br>\u4f8b\u5982\uff1aint? <strong><em>val <\/em><\/strong>= <strong><em>obj<\/em><\/strong>?.Length;<\/li>\n\n\n\n<li>C# 8.0\u5f15\u5165\u4e86\u7a7a\u5408\u5e76\u8fd0\u7b97\u7b26 ??, \"<strong><em>expression1 <\/em><\/strong>?? <strong><em>expression2<\/em><\/strong>\"\u8868\u793a<strong><em>expression1<\/em><\/strong>\u4e0d\u4e3a\u7a7a\u8fd4\u56de<strong><em>expression1<\/em><\/strong>\uff0c\u5426\u5219\u8fd4\u56de<strong><em>expression2<\/em><\/strong>.<\/li>\n\n\n\n<li>Kotlin \u53ef\u7a7a\u7c7b\u578b\u5b89\u5168\u8c03\u7528\u7684\u8fd0\u7b97\u7b26\u88ab\u79f0\u4e3a\u5b89\u5168\u8c03\u7528\u7b26\uff0c\u548cC#\u4e00\u6837\u7528 \"?.\". <\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u53ef\u7a7a\u7c7b\u578b\u5b89\u5168\u8c03\u7528\u9ed8\u8ba4\u8fd4\u56de\u503c<\/h3>\n\n\n\n<p>  \u6709\u65f6\uff0c\u5c3d\u7ba1\u4e00\u4e2a\u7c7b\u578b\u662fnull, \u4f46\u4e0d\u5e0c\u671b\u5b89\u5168\u8c03\u7528\u540e\u8fd4\u56de\u7684\u4f9d\u7136\u662fnull.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Kotlin \u63d0\u4f9b\u4e86Elvis\u8fd0\u7b97\u7b26 ?: \u53ef\u5ba2\u5236\u5316\u9ed8\u8ba4\u8fd4\u56denull\u7684\u95ee\u9898\u3002\n<ul class=\"wp-block-list\">\n<li>\u4f8b\u5982\u5f53name\u4e3anull\uff0c\u9ed8\u8ba4\u8fd4\u56de\u957f\u5ea6\u4e3a1\uff1avar <strong><em>len <\/em><\/strong>= <strong><em>name<\/em><\/strong>?.length ?: 1;<br><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u975e\u7a7a\u65ad\u8a00<\/h3>\n\n\n\n<p>  \u5c3d\u7ba1\u5b89\u5168\u8c03\u7528\u53ef\u4ee5\u8ba9null\u7c7b\u578b\u66f4\"\u5b89\u5168\", \u6709\u65f6\u8fd8\u662f\u5e0c\u671b\u78b0\u5230null\u4f1a\u629b\u51fa\u5f02\u5e38\u89e3\u51b3\u4e0d\u9884\u671f\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Kotlin \u63d0\u4f9b\u975e\u7a7a\u65ad\u8a00 !!. \u5f3a\u5236\u8981\u6c42\u53d8\u91cf\u4e0d\u662fnull, \u5982\u679c\u662fnull\u4f1a\u629b\u51fa\u5f02\u5e38\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u7f16\u7a0b\u4e2d\u4f1a\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u7528\u6574\u578b\u6b63\u6570\u4ee3\u8868\u6570\u636e\u7684\u503c\uff0c-1\u4ee3\u8868\u9519\u8bef\u3002\u7a0b\u5e8f\u5458\u5fc5\u987b\u5206\u6e05\u695a\u8fd9\u4e24\u79cd\u60c5\u51b5\uff0c\u907f\u514d\u5c06-1\u5f53\u505a\u662f\u6570\u636e\u6709\u6548\u503c\u3002\u53ef\u7a7a\u7c7b\u578b\u6b63\u662f\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u3002 \u5f00\u542f\u53ef\u7a7a\u7c7b\u578b null\u503c\u6761\u4ef6\u8fd0\u7b97\u7b26 \u53ef\u7a7a\u7c7b\u578b\u5b89\u5168\u8c03\u7528&#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":[299],"tags":[],"class_list":["post-2042","post","type-post","status-publish","format-standard","hentry","category-think"],"views":55,"_links":{"self":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/2042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/comments?post=2042"}],"version-history":[{"count":9,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/2042\/revisions"}],"predecessor-version":[{"id":4003,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/posts\/2042\/revisions\/4003"}],"wp:attachment":[{"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/media?parent=2042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/categories?post=2042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.minicoda.com\/index.php\/wp-json\/wp\/v2\/tags?post=2042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}