{"id":2034,"date":"2021-09-19T00:15:43","date_gmt":"2021-09-18T16:15:43","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=2034"},"modified":"2022-02-16T21:46:51","modified_gmt":"2022-02-16T13:46:51","slug":"logic-if-switch","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2021\/09\/19\/logic-if-switch\/","title":{"rendered":"D-26-\u908f\u8f2f logic ? if ? switch"},"content":{"rendered":"<h1>\u8a8d\u8b58\u8b8a\u6578\u4e4b\u5f8c<\/h1>\n<p>\u6628\u5929\u5c0f\u5149\u5f9e\u5927\u982d\u90a3\u88e1\u8a8d\u8b58\u4e86\u8b8a\u6578\uff0c\u4e0d\u904e\u5149\u6709\u8b8a\u6578\u53ef\u6c92\u8fa6\u6cd5\u505a\u4e8b\u7684\uff0c\u6240\u4ee5\u4eca\u5929\u4f86\u770b\u770b\u5927\u982d\u8981\u600e\u9ebc\u544a\u8a34\u5c0f\u5149\u908f\u8f2f\u7684\u554f\u984c\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u908f\u8f2f logic<\/h2>\n<p>\u300c\u524d\u8f29\uff0c\u6211\u6e96\u5099\u597d\u8981\u958b\u767c\u4e86\uff0c\u4eca\u5929\u8981\u958b\u767c\u4ec0\u9ebc\u5462\uff1f\u300d<br \/>\n\u8ddf\u6628\u5929\u4e00\u5927\u65e9\u4e00\u6a23\uff0c\u5c0f\u5149\u4e00\u5230\u516c\u53f8\u5c31\u7528\u7368\u7279\u7684\u65b9\u5f0f\u4f86\u6253\u62db\u547c\uff0c\u800c\u5927\u982d\u4f9d\u820a\u662f\u57cb\u982d\u65bc\u773e\u591a\u6587\u4ef6\u4e4b\u4e2d\uff0c\u5e36\u5c0f\u5149\u8aaa\u5b8c\u4e94\u79d2\u5f8c\u5927\u982d\u624d\u5f9e\u958b\u767c\u7684\u72c0\u614b\u56de\u5fa9\u7684\u6b63\u5e38\u6a21\u5f0f\u3002<br \/>\n\u300c\u4f60\u4eca\u5929\u60f3\u8981\u958b\u767c\u4ec0\u9ebc\u5462\uff1f\u300d<br \/>\n\u807d\u5230\u524d\u8f29\u9019\u9ebc\u554f\u5c0f\u5149\u4e5f\u958b\u59cb\u8a8d\u771f\u601d\u8003\u4e86\u8d77\u4f86\uff0c\u4e0d\u904e\u904e\u4e86\u5e7e\u5206\u9418\u5f8c\u4f3c\u4e4e\u6c92\u6709\u7d50\u8ad6\u7684\u770b\u8457\u5927\u982d\u5e0c\u671b\u5927\u982d\u7d66\u4e9b\u610f\u898b\u3002<br \/>\n\u300c\u90a3\u6211\u5011\u4f86\u958b\u767c\u4e00\u500b\u5fc3\u60c5\u8868\u73fe\u5668\u5427\u3002\u300d<br \/>\n\u807d\u5230\u524d\u8f29\u7684\u63d0\u6848\u5f8c\u5c0f\u5149\u6574\u500b\u773c\u775b\u4eae\u4e86\u8d77\u4f86\uff0c\u800c\u4e14\u6574\u500b\u4eba\u5c55\u73fe\u51fa\u96c0\u96c0\u6b32\u8a66\u7684\u72c0\u614b\u4f86\u7b49\u5f85\u5927\u982d\u7684\u6307\u4ee4\u3002<br \/>\n\u300c\u90a3\u4f60\u6709\u4ec0\u9ebc\u4e0d\u4e86\u89e3\u7684\u5730\u65b9\u55ce\uff0c\u9084\u662f\u8aaa\u4f60\u53ef\u4ee5\u958b\u59cb\u958b\u767c\u4e86\uff1f\u300d<br \/>\n\u807d\u4e86\u5927\u982d\u7684\u554f\u984c\u5f8c\u5c0f\u5149\u8a8d\u771f\u7684\u601d\u8003\u4e86\u4e00\u4e0b\uff0c\u904e\u4e86\u5e7e\u79d2\u5f8c\u5c0f\u5149\u9019\u6a23\u554f\u5230\u3002<br \/>\n\u300c\u524d\u8f29\u8acb\u554f\u908f\u8f2f\u8981\u600e\u9ebc\u6a23\u8655\u7406\u5462\uff1f\u300d<br \/>\n\u300c\u54c8\u54c8\u54c8\uff0c\u6211\u5c31\u77e5\u9053\u4f60\u6703\u6709\u554f\u984c\uff0c\u8b93\u6211\u4f86\u544a\u8a34\u4f60\u908f\u8f2f\u5224\u65b7\u5f0f\u7684\u5beb\u6cd5\u300d<\/p>\n<h3>\u908f\u8f2f\u5224\u65b7\u5f0f\u7684\u4ecb\u7d39<\/h3>\n<p>\u9996\u5148\u6211\u5011\u5148\u4f86\u8aaa\u660e\u8981\u958b\u767c\u7684\u6771\u897f\uff0c\u7c21\u55ae\u4f86\u8aaa\u5c31\u662f\u6211\u5011\u6709\u500b\u8b8a\u6578\uff0c\u7136\u5f8c\u4f9d\u64da\u8b8a\u6578\u4f86\u986f\u793a\u5167\u5bb9\uff0c\u6839\u64da\u9019\u500b\u9700\u6c42\u6211\u5011\u8981\u5b78\u7684\u662f\u4ee5\u4e0b\u5169\u7a2e\u908f\u8f2f\u5224\u65b7\u5f0f\u3002<\/p>\n<h4>if else<\/h4>\n<p>\u9996\u5148\u8981\u4ecb\u7d39\u7684\u662f<code>if else<\/code>\u5224\u65b7\u5f0f\uff0c\u7c21\u55ae\u7684\u8aaa\u660e\u5c31\u662f\u5224\u65b7\u5f0f\u6210\u7acb\u6642\u53ef\u4ee5\u57f7\u884c\u5340\u584a\u5167\u7684\u7a0b\u5f0f\uff0c\u6240\u4ee5\u7a0b\u5f0f\u5beb\u51fa\u4f86\u6703\u50cf\u4e0b\u5217\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-cs\">var isHappy = false;\nif (isHappy)\n{\n    Console.WriteLine(&quot;\u6211\u958b\u5fc3&quot;);\n}\nelse\n{\n    Console.WriteLine(&quot;\u6211\u4e0d\u958b\u5fc3&quot;);\n}<\/code><\/pre>\n<h4>switch case<\/h4>\n<p>\u4ecb\u7d39\u5b8c<code>if else<\/code>\u5224\u65b7\u5f0f\u4e4b\u5f8c\u63a5\u4e0b\u4f86\u8981\u4ecb\u7d39\u7684\u662f<code>switch case<\/code>\u5224\u65b7\u5f0f\u3002\u8ddf<code>if else<\/code>\u5224\u65b7\u5f0f\u4e0d\u540c\u7684\u5730\u65b9\u662f\uff0c\u7576<code>switch<\/code>\u5167\u7684\u8b8a\u6578\u8ddf<code>case<\/code>\u76f8\u540c\u6642\u6703\u57f7\u884c\u5340\u584a\u5167\u7684\u7a0b\u5f0f\uff0c\u5982\u679c\u90fd\u6c92\u6709\u76f8\u540c\u7684\u6703\u57f7\u884c<code>default<\/code>\u7684\u7a0b\u5f0f\uff0c\u6240\u4ee5\u7c21\u55ae\u8aaa\u8d77\u4f86\u5f0f\u5b50\u5982\u4e0b\uff0c\u4e0d\u904e\u8981\u6ce8\u610f<code>break<\/code>\u8981\u8a18\u5f97\u653e\u7f6e\u5426\u5247\u7a0b\u5f0f\u6703\u6709\u81ed\u87f2\u3002<\/p>\n<pre><code class=\"language-csharp\">var isHappy = true;\nswitch(isHappy)\n{\n    case true:\n        Console.WriteLine(&quot;\u6211\u958b\u5fc3&quot;);\n        break;\n    default:\n        Console.WriteLine(&quot;\u6211\u4e0d\u958b\u5fc3&quot;);\n        break;\n}<\/code><\/pre>\n<h3>\u9032\u968e\u7684\u9ad4\u9a57<\/h3>\n<p>\u300c\u597d\u56c9\uff0c\u4ecb\u7d39\u7d66\u4f60\u57fa\u672c\u7684\u908f\u8f2f\u5224\u65b7\u77e5\u8b58\u56c9\uff0c\u4e0d\u904e\u554f\u984c\u4f86\u4e86\u5982\u679c\u66f4\u9032\u4e00\u6b65\u8981\u4f60\u5427\u5fc3\u60c5\u5206\u7b49\u7d1a\u4f86\u8868\u73fe\u5fc3\u60c5\u72c0\u6cc1\u6642\u7a0b\u5f0f\u8a72\u600e\u9ebc\u8655\u7406\u5462\uff1f\u300d<br \/>\n\u4ecb\u7d39\u5b8c\u908f\u8f2f\u5224\u65b7\u5f0f\u5f8c\uff0c\u5927\u982d\u51fa\u4e86\u4e00\u500b\u984c\u76ee\u7d66\u5c0f\u5149\uff0c\u9019\u6642\u5c0f\u5149\u601d\u8003\u4e86\u4e00\u4e0b\uff0c\u904e\u4e86\u5e7e\u79d2\u5f8c\u5c0f\u5149\u9019\u9ebc\u8aaa\u3002<br \/>\n\u300c\u597d\u7684\u524d\u8f29\u770b\u6211\u7684\u300d<br \/>\n\u8aaa\u5b8c\u5f8c\u5c0f\u5149\u5c31\u5750\u4e0b\u5f8c\u5beb\u4e86\u9019\u6bb5\u5f0f\u5b50\u3002<\/p>\n<pre><code class=\"language-csharp\">var happyLevel = 1;\nif (happyLevel &gt; 5)\n{\n    Console.WriteLine(&quot;\u6211\u975e\u5e38\u9ad8\u8208&quot;);\n}\nelse if (happyLevel &gt; 0)\n{\n    Console.WriteLine(&quot;\u6211\u5f88\u9ad8\u8208&quot;);\n}\nelse\n{\n    Console.WriteLine(&quot;\u6211\u4e0d\u958b\u5fc3&quot;);\n}<\/code><\/pre>\n<h2>\u5f8c\u8a18<\/h2>\n<p>\u5c0f\u5149\u7528<code>if else<\/code>\u7684\u65b9\u5f0f\u4f86\u5b8c\u6210\u524d\u8f29\u51fa\u7684\u984c\u76ee\uff0c\u63a5\u4e0b\u4f86\u8b80\u8005\u5011\u53ef\u4ee5\u8a66\u8457\u7528<code>switch case<\/code>\u4f86\u5beb\u5beb\u770b\u5594\uff0c\u63a5\u4e0b\u4f86\u660e\u5929\u5c0f\u5149\u6703\u9047\u5230\u4ec0\u9ebc\u6a23\u7684\u554f\u984c\u5462\uff0c\u656c\u8acb\u671f\u5f85\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8a8d\u8b58\u8b8a\u6578\u4e4b\u5f8c \u6628\u5929\u5c0f\u5149\u5f9e\u5927\u982d\u90a3\u88e1\u8a8d\u8b58\u4e86\u8b8a\u6578\uff0c\u4e0d\u904e\u5149\u6709\u8b8a\u6578\u53ef\u6c92\u8fa6\u6cd5\u505a\u4e8b\u7684\uff0c\u6240\u4ee5\u4eca\u5929\u4f86\u770b\u770b\u5927\u982d\u8981\u600e\u9ebc\u544a\u8a34\u5c0f\u5149\u908f\u8f2f\u7684 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2021\/09\/19\/logic-if-switch\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008D-26-\u908f\u8f2f logic ? if ? switch\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[90,71,92],"class_list":["post-2034","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2021ironman","tag-c","tag-dotnetcore"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=2034"}],"version-history":[{"count":19,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2034\/revisions"}],"predecessor-version":[{"id":2946,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/2034\/revisions\/2946"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}