{"id":48426,"date":"2024-12-02T13:11:52","date_gmt":"2024-12-02T05:11:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48426\/"},"modified":"2024-12-02T13:11:52","modified_gmt":"2024-12-02T05:11:52","slug":"golang-%e4%b8%ad-var-%e5%92%8c-type-%e5%ae%9a%e4%b9%89%e7%bb%93%e6%9e%84%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48426\/","title":{"rendered":"Golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aGolang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1730028100671e224489a42.jpg\" class=\"aligncenter\" title=\"Golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" alt=\"Golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u7684\u533a\u522b<\/strong><\/p>\n<p>\u5728 golang \u4e2d\uff0c\u4f7f\u7528 var \u548c type \u5b9a\u4e49\u7ed3\u6784\u65f6\uff0c\u4e24\u8005\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002<\/p>\n<p>\u5f53\u4f7f\u7528 var \u5b9a\u4e49\u7ed3\u6784\u65f6\uff0c\u672c\u8d28\u4e0a\u662f\u5728\u521b\u5efa\u8be5\u7ed3\u6784\u7c7b\u578b\u7684\u533f\u540d\u5b9e\u4f8b\u3002\u8fd9\u610f\u5473\u7740\u8be5\u7ed3\u6784\u6ca1\u6709\u660e\u786e\u7684\u540d\u79f0\uff0c\u53ea\u80fd\u901a\u8fc7\u53d8\u91cf\u540d\u6765\u8bbf\u95ee\u5b83\u7684\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>var people struct {\n    name string\n}\n\npeople.name = \"john doe\"\n\nfmt.println(people.name) \/\/ \u8f93\u51fa \"john doe\"<\/pre>\n<p>\u53e6\u4e00\u65b9\u9762\uff0c\u4f7f\u7528 type \u5b9a\u4e49\u7ed3\u6784\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7ed3\u6784\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u53ef\u7528\u4e8e\u58f0\u660e\u591a\u4e2a\u5177\u6709\u76f8\u540c\u5b57\u6bb5\u7684\u7ed3\u6784\u5b9e\u4f8b\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>type People struct {\n    name string\n}\n\nvar john = People{name: \"John Doe\"}\n\nfmt.Println(john.name) \/\/ \u8f93\u51fa \"John Doe\"<\/pre>\n<p>\u5728\u8be5\u793a\u4f8b\u4e2d\uff0cpeople \u662f\u4e00\u4e2a\u7528\u6237\u5b9a\u4e49\u7684\u7ed3\u6784\u7c7b\u578b\uff0cjohn \u662f\u8be5\u7c7b\u578b\u7684\u5b9e\u4f8b\u3002\u901a\u8fc7\u4f7f\u7528\u7ed3\u6784\u540d\uff08people\uff09\uff0c\u6211\u4eec\u53ef\u4ee5\u8bbf\u95ee\u7ed3\u6784\u7684\u5b57\u6bb5\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u533f\u540d\u53d8\u91cf\u540d\uff08people\uff09\u3002<\/p>\n<p>\u603b\u4f53\u800c\u8a00\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528 type \u5b9a\u4e49\u7ed3\u6784\u662f\u66f4\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u521b\u5efa\u5177\u6709\u660e\u786e\u540d\u79f0\u7684\u7ed3\u6784\u7c7b\u578b\uff0c\u5e76\u4f7f\u4ee3\u7801\u66f4\u6613\u4e8e\u7406\u89e3\u548c\u7ef4\u62a4\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aGolang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aGolang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b golang \u4e2d var \u548c type \u5b9a\u4e49\u7ed3\u6784\u7684\u533a\u522b \u5728 golang \u4e2d\uff0c\u4f7f\u7528 var \u548c type \u5b9a\u4e49\u7ed3\u6784\u65f6\uff0c\u4e24\u8005\u4e4b\u95f4\u5b58\u5728\u4e00\u4e9b\u5173\u952e\u5dee\u5f02\u3002 \u5f53\u4f7f\u7528 var \u5b9a\u4e49\u7ed3\u6784\u65f6\uff0c\u672c\u8d28\u4e0a\u662f\u5728\u521b\u5efa\u8be5\u7ed3\u6784\u7c7b\u578b\u7684\u533f\u540d\u5b9e\u4f8b\u3002\u8fd9\u610f\u5473\u7740\u8be5\u7ed3\u6784\u6ca1\u6709\u660e\u786e\u7684\u540d\u79f0\uff0c\u53ea\u80fd\u901a\u8fc7\u53d8\u91cf\u540d\u6765\u8bbf\u95ee\u5b83\u7684\u5b57\u6bb5\u3002 \u793a\u4f8b\uff1a var people struct { name string } people.name = &#8220;john doe&#8221; fmt.println(people.name) \/\/ \u8f93\u51fa &#8220;john doe&#8221; \u53e6\u4e00\u65b9\u9762\uff0c\u4f7f\u7528 type \u5b9a\u4e49\u7ed3\u6784\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7ed3\u6784\u7c7b\u578b\uff0c\u8be5\u7c7b\u578b\u53ef\u7528\u4e8e\u58f0\u660e\u591a\u4e2a\u5177\u6709\u76f8\u540c\u5b57\u6bb5\u7684\u7ed3\u6784\u5b9e\u4f8b\u3002 \u793a\u4f8b\uff1a type People struct { name string [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48426","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48426"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48426\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}