{"id":236227,"date":"2022-02-28T09:39:28","date_gmt":"2022-02-28T01:39:28","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=236227"},"modified":"2022-02-21T15:40:06","modified_gmt":"2022-02-21T07:40:06","slug":"learn-about-c","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/learn-about-c.html","title":{"rendered":"\u4e86\u89e3\u4e0bC# \u5224\u65ad"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nC# \u662f\u4e00\u4e2a\u73b0\u4ee3\u7684\u3001\u901a\u7528\u7684\u3001\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u662f\u7531\u5fae\u8f6f\uff08Microsoft\uff09\u5f00\u53d1\u7684\uff0c\u7531 Ecma \u548c ISO \u6838\u51c6\u8ba4\u53ef\u7684\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u5224\u65ad\u7ed3\u6784\u8981\u6c42\u7a0b\u5e8f\u5458\u6307\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u8981\u8bc4\u4f30\u6216\u6d4b\u8bd5\u7684\u6761\u4ef6\uff0c\u4ee5\u53ca\u6761\u4ef6\u4e3a\u771f\u65f6\u8981\u6267\u884c\u7684\u8bed\u53e5\uff08\u5fc5\u9700\u7684\uff09\u548c\u6761\u4ef6\u4e3a\u5047\u65f6\u8981\u6267\u884c\u7684\u8bed\u53e5\uff08\u53ef\u9009\u7684\uff09\u3002<\/p>\n

\u4e0b\u9762\u662f\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u4e2d\u5178\u578b\u7684\u5224\u65ad\u7ed3\u6784\u7684\u4e00\u822c\u5f62\u5f0f\uff1a
\n\"\"<\/p>\n

\u5224\u65ad\u8bed\u53e5<\/strong><\/div>\n

C# \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u7c7b\u578b\u7684\u5224\u65ad\u8bed\u53e5\u3002\u70b9\u51fb\u94fe\u63a5\u67e5\u770b\u6bcf\u4e2a\u8bed\u53e5\u7684\u7ec6\u8282\u3002<\/p>\n\n\n\n\n\n\n\n\n
\u8bed\u53e5<\/th>\n\u63cf\u8ff0<\/th>\n<\/tr>\n
if \u8bed\u53e5<\/a><\/td>\n\u4e00\u4e2a if \u8bed\u53e5<\/b> \u7531\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\u540e\u8ddf\u4e00\u4e2a\u6216\u591a\u4e2a\u8bed\u53e5\u7ec4\u6210\u3002<\/td>\n<\/tr>\n
if...else \u8bed\u53e5<\/a><\/td>\n\u4e00\u4e2a if \u8bed\u53e5<\/b> \u540e\u53ef\u8ddf\u4e00\u4e2a\u53ef\u9009\u7684 else \u8bed\u53e5<\/b>\uff0celse \u8bed\u53e5\u5728\u5e03\u5c14\u8868\u8fbe\u5f0f\u4e3a\u5047\u65f6\u6267\u884c\u3002<\/td>\n<\/tr>\n
\u5d4c\u5957 if \u8bed\u53e5<\/a><\/td>\n\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2a if<\/b> \u6216 else if<\/b> \u8bed\u53e5\u5185\u4f7f\u7528\u53e6\u4e00\u4e2a if<\/b> \u6216 else if<\/b> \u8bed\u53e5\u3002<\/td>\n<\/tr>\n
switch \u8bed\u53e5<\/a><\/td>\n\u4e00\u4e2a switch<\/b> \u8bed\u53e5\u5141\u8bb8\u6d4b\u8bd5\u4e00\u4e2a\u53d8\u91cf\u7b49\u4e8e\u591a\u4e2a\u503c\u65f6\u7684\u60c5\u51b5\u3002<\/td>\n<\/tr>\n
\u5d4c\u5957 switch \u8bed\u53e5<\/a><\/td>\n\u60a8\u53ef\u4ee5\u5728\u4e00\u4e2a switch<\/b> \u8bed\u53e5\u5185\u4f7f\u7528\u53e6\u4e00\u4e2a switch <\/b> \u8bed\u53e5\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
? : \u8fd0\u7b97\u7b26<\/strong><\/div>\n

\u6211\u4eec\u5df2\u7ecf\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d\u8bb2\u89e3\u4e86 \u6761\u4ef6\u8fd0\u7b97\u7b26 ? :\uff0c\u53ef\u4ee5\u7528\u6765\u66ff\u4ee3 if...else \u8bed\u53e5\u3002\u5b83\u7684\u4e00\u822c\u5f62\u5f0f\u5982\u4e0b\uff1a<\/p>\n

Exp1 ? Exp2 : Exp3;<\/pre>\n

\u5176\u4e2d\uff0cExp1\u3001Exp2 \u548c Exp3 \u662f\u8868\u8fbe\u5f0f\u3002\u8bf7\u6ce8\u610f\uff0c\u5192\u53f7\u7684\u4f7f\u7528\u548c\u4f4d\u7f6e\u3002<\/p>\n

? \u8868\u8fbe\u5f0f\u7684\u503c\u662f\u7531 Exp1 \u51b3\u5b9a\u7684\u3002\u5982\u679c Exp1 \u4e3a\u771f\uff0c\u5219\u8ba1\u7b97 Exp2 \u7684\u503c\uff0c\u7ed3\u679c\u5373\u4e3a\u6574\u4e2a ? \u8868\u8fbe\u5f0f\u7684\u503c\u3002\u5982\u679c Exp1 \u4e3a\u5047\uff0c\u5219\u8ba1\u7b97 Exp3 \u7684\u503c\uff0c\u7ed3\u679c\u5373\u4e3a\u6574\u4e2a ? \u8868\u8fbe\u5f0f\u7684\u503c\u3002
\n?: \u4e3e\u4f8b \u4e0b\u9762\u662f\u9636\u4e58\u7684\u9012\u5f52\u7b97\u6cd5\uff0c\u5176\u4e2d\u5224\u65ad\u6761\u4ef6\u5982\u679c num>0 \u5219\u8fd4\u56de num *Jc(num - 1)\uff0c\u5426\u5219\u8fd4\u56de 1\u3002<\/p>\n

using System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nnamespace jiecheng\r\n{\r\n    class jiecheng\r\n    {\r\n        public int Jc(int num)\r\n        {\r\n            \r\n            return num > 0 ? num *Jc(num - 1):1;  \/\/\u5982\u679cnum>0\u5219\u8fd4\u56denum *Jc(num - 1)\uff0c\u5426\u5219\u8fd4\u56de1\r\n        }\r\n    }\r\n\r\n    class excutejiecheng\r\n  \r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            jiecheng n = new jiecheng();\r\n            int result = n.Jc(Convert.ToInt16(Console.ReadLine()));\r\n            Console.WriteLine(\"result is {0}\",result);\r\n            Console.ReadKey();\r\n        }\r\n    }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5224\u65ad\u7ed3\u6784\u8981\u6c42\u7a0b\u5e8f\u5458\u6307\u5b9a\u4e00\u4e2a\u6216\u591a\u4e2a\u8981\u8bc4\u4f30\u6216\u6d4b\u8bd5\u7684\u6761\u4ef6\uff0c\u4ee5\u53ca\u6761\u4ef6\u4e3a\u771f\u65f6\u8981\u6267\u884c\u7684\u8bed\u53e5\uff08\u5fc5\u9700\u7684\uff09\u548c\u6761\u4ef6\u4e3a\u5047\u65f6\u8981\u6267\u884c\u7684\u8bed […]<\/p>\n","protected":false},"author":321,"featured_media":236229,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-236227","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=236227"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236227\/revisions"}],"predecessor-version":[{"id":236232,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236227\/revisions\/236232"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/236229"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=236227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=236227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=236227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}