{"id":234082,"date":"2022-01-26T10:31:54","date_gmt":"2022-01-26T02:31:54","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=234082"},"modified":"2022-01-08T18:35:51","modified_gmt":"2022-01-08T10:35:51","slug":"about-c-variables","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/about-c-variables.html","title":{"rendered":"\u4e86\u89e3\u4e0bC# \u53d8\u91cf"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e00\u4e2a\u53d8\u91cf\u53ea\u4e0d\u8fc7\u662f\u4e00\u4e2a\u4f9b\u7a0b\u5e8f\u64cd\u4f5c\u7684\u5b58\u50a8\u533a\u7684\u540d\u5b57\u3002\u5728 C# \u4e2d\uff0c\u6bcf\u4e2a\u53d8\u91cf\u90fd\u6709\u4e00\u4e2a\u7279\u5b9a\u7684\u7c7b\u578b\uff0c\u7c7b\u578b\u51b3\u5b9a\u4e86\u53d8\u91cf\u7684\u5185\u5b58\u5927\u5c0f\u548c\u5e03\u5c40\u3002\u8303\u56f4\u5185\u7684\u503c\u53ef\u4ee5\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u53ef\u4ee5\u5bf9\u53d8\u91cf\u8fdb\u884c\u4e00\u7cfb\u5217\u64cd\u4f5c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u6211\u4eec\u5df2\u7ecf\u8ba8\u8bba\u4e86\u5404\u79cd\u6570\u636e\u7c7b\u578b\u3002C# \u4e2d\u63d0\u4f9b\u7684\u57fa\u672c\u7684\u503c\u7c7b\u578b\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b\uff1a<\/p>\n\n\n\n\n\n\n\n\n
\u7c7b\u578b<\/th>\n\u4e3e\u4f8b<\/th>\n<\/tr>\n
\u6574\u6570\u7c7b\u578b<\/td>\nsbyte\u3001byte\u3001short\u3001ushort\u3001int\u3001uint\u3001long\u3001ulong \u548c char<\/td>\n<\/tr>\n
\u6d6e\u70b9\u578b<\/td>\nfloat \u548c double<\/td>\n<\/tr>\n
\u5341\u8fdb\u5236\u7c7b\u578b<\/td>\ndecimal<\/td>\n<\/tr>\n
\u5e03\u5c14\u7c7b\u578b<\/td>\ntrue \u6216 false \u503c\uff0c\u6307\u5b9a\u7684\u503c<\/td>\n<\/tr>\n
\u7a7a\u7c7b\u578b<\/td>\n\u53ef\u4e3a\u7a7a\u503c\u7684\u6570\u636e\u7c7b\u578b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

C# \u5141\u8bb8\u5b9a\u4e49\u5176\u4ed6\u503c\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u6bd4\u5982 enum\uff0c\u4e5f\u5141\u8bb8\u5b9a\u4e49\u5f15\u7528\u7c7b\u578b\u53d8\u91cf\uff0c\u6bd4\u5982 class\u3002\u8fd9\u4e9b\u6211\u4eec\u5c06\u5728\u4ee5\u540e\u7684\u7ae0\u8282\u4e2d\u8fdb\u884c\u8ba8\u8bba\u3002\u5728\u672c\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u53ea\u7814\u7a76\u57fa\u672c\u53d8\u91cf\u7c7b\u578b\u3002<\/p>\n

C# \u4e2d\u7684\u53d8\u91cf\u5b9a\u4e49<\/strong><\/div>\n

C# \u4e2d\u53d8\u91cf\u5b9a\u4e49\u7684\u8bed\u6cd5\uff1a<\/p>\n

<data_type><\/span> <\/span><variable_list><\/span>;<\/span><\/pre>\n

\u5728\u8fd9\u91cc\uff0cdata_type \u5fc5\u987b\u662f\u4e00\u4e2a\u6709\u6548\u7684 C# \u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u662f char\u3001int\u3001float\u3001double \u6216\u5176\u4ed6\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\u3002variable_list \u53ef\u4ee5\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7528\u9017\u53f7\u5206\u9694\u7684\u6807\u8bc6\u7b26\u540d\u79f0\u7ec4\u6210\u3002<\/p>\n

\u4e00\u4e9b\u6709\u6548\u7684\u53d8\u91cf\u5b9a\u4e49\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

int i, j, k;\r\nchar c, ch;\r\nfloat f, salary;\r\ndouble d;<\/pre>\n

\u60a8\u53ef\u4ee5\u5728\u53d8\u91cf\u5b9a\u4e49\u65f6\u8fdb\u884c\u521d\u59cb\u5316\uff1a<\/p>\n

int i = 100;<\/pre>\n
C# \u4e2d\u7684\u53d8\u91cf\u521d\u59cb\u5316<\/strong><\/div>\n

\u53d8\u91cf\u901a\u8fc7\u5728\u7b49\u53f7\u540e\u8ddf\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\u8fdb\u884c\u521d\u59cb\u5316\uff08\u8d4b\u503c\uff09\u3002\u521d\u59cb\u5316\u7684\u4e00\u822c\u5f62\u5f0f\u4e3a\uff1a<\/p>\n

variable_name = value;<\/pre>\n

\u53d8\u91cf\u53ef\u4ee5\u5728\u58f0\u660e\u65f6\u88ab\u521d\u59cb\u5316\uff08\u6307\u5b9a\u4e00\u4e2a\u521d\u59cb\u503c\uff09\u3002\u521d\u59cb\u5316\u7531\u4e00\u4e2a\u7b49\u53f7\u540e\u8ddf\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\u7ec4\u6210\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

<data_type><\/span> <\/span><variable_name><\/span> = value;<\/span><\/pre>\n

\u4e00\u4e9b\u5b9e\u4f8b\uff1a<\/p>\n

int d = 3, f = 5;    \/* \u521d\u59cb\u5316 d \u548c f. *\/\r\nbyte z = 22;         \/* \u521d\u59cb\u5316 z. *\/\r\ndouble pi = 3.14159; \/* \u58f0\u660e pi \u7684\u8fd1\u4f3c\u503c *\/\r\nchar x = 'x';        \/* \u53d8\u91cf x \u7684\u503c\u4e3a 'x' *\/<\/pre>\n

\u6b63\u786e\u5730\u521d\u59cb\u5316\u53d8\u91cf\u662f\u4e00\u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\uff0c\u5426\u5219\u6709\u65f6\u7a0b\u5e8f\u4f1a\u4ea7\u751f\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\u3002<\/p>\n

\u8bf7\u770b\u4e0b\u9762\u7684\u5b9e\u4f8b\uff0c\u4f7f\u7528\u4e86\u5404\u79cd\u7c7b\u578b\u7684\u53d8\u91cf\uff1a<\/p>\n

\u5b9e\u4f8b<\/strong><\/p>\n

namespace<\/span> VariableDefinition\r\n{\r\n    class<\/span> Program\r\n    {\r\n        static<\/span> void<\/span> Main(<\/span>string<\/span>[<\/span>]<\/span> args)\r\n        {\r\n            short<\/span> a;\r\n            int<\/span> b ;\r\n            double<\/span> c;\r\n            \/* \u5b9e\u9645\u521d\u59cb\u5316 *\/\r\n            a =<\/span> 10<\/span>;\r\n            b =<\/span> 20<\/span>;\r\n            c =<\/span> a +<\/span> b;\r\n            Console.<\/span>WriteLine<\/span>(<\/span>\"a = {0}, b = {1}, c = {2}\"<\/span>, a, b, c)<\/span>;\r\n            Console.<\/span>ReadLine<\/span>(<\/span>)<\/span>;\r\n        }\r\n    }\r\n}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n

\u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u548c\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff1a<\/p>\n

a = 10, b = 20, c = 30<\/pre>\n
\u63a5\u53d7\u6765\u81ea\u7528\u6237\u7684\u503c<\/strong><\/div>\n

System \u547d\u540d\u7a7a\u95f4\u4e2d\u7684 Console \u7c7b\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 ReadLine()\uff0c\u7528\u4e8e\u63a5\u6536\u6765\u81ea\u7528\u6237\u7684\u8f93\u5165\uff0c\u5e76\u628a\u5b83\u5b58\u50a8\u5230\u4e00\u4e2a\u53d8\u91cf\u4e2d\u3002
\n\u4f8b\u5982\uff1a<\/p>\n

int num;\r\nnum = Convert.ToInt32(Console.ReadLine());<\/pre>\n

\u51fd\u6570 Convert.ToInt32() \u628a\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u8f6c\u6362\u4e3a int \u6570\u636e\u7c7b\u578b\uff0c\u56e0\u4e3a Console.ReadLine() \u53ea\u63a5\u53d7\u5b57\u7b26\u4e32\u683c\u5f0f\u7684\u6570\u636e\u3002<\/p>\n

C# \u4e2d\u7684 Lvalues \u548c Rvalues<\/strong><\/div>\n

C# \u4e2d\u7684\u4e24\u79cd\u8868\u8fbe\u5f0f\uff1a<\/p>\n

    \n
  1. lvalue\uff1alvalue \u8868\u8fbe\u5f0f\u53ef\u4ee5\u51fa\u73b0\u5728\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u6216\u53f3\u8fb9\u3002<\/li>\n
  2. rvalue\uff1arvalue \u8868\u8fbe\u5f0f\u53ef\u4ee5\u51fa\u73b0\u5728\u8d4b\u503c\u8bed\u53e5\u7684\u53f3\u8fb9\uff0c\u4e0d\u80fd\u51fa\u73b0\u5728\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u3002<\/li>\n<\/ol>\n

    \u53d8\u91cf\u662f lvalue \u7684\uff0c\u6240\u4ee5\u53ef\u4ee5\u51fa\u73b0\u5728\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u3002\u6570\u503c\u662f rvalue \u7684\uff0c\u56e0\u6b64\u4e0d\u80fd\u88ab\u8d4b\u503c\uff0c\u4e0d\u80fd\u51fa\u73b0\u5728\u8d4b\u503c\u8bed\u53e5\u7684\u5de6\u8fb9\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u6709\u6548\u7684\u8bed\u53e5\uff1a<\/p>\n

    int g = 20;<\/pre>\n

    \u4e0b\u9762\u662f\u4e00\u4e2a\u65e0\u6548\u7684\u8bed\u53e5\uff0c\u4f1a\u4ea7\u751f\u7f16\u8bd1\u65f6\u9519\u8bef\uff1a<\/p>\n

    10 = 20;<\/pre>\n","protected":false},"excerpt":{"rendered":"

    \u6211\u4eec\u5df2\u7ecf\u8ba8\u8bba\u4e86\u5404\u79cd\u6570\u636e\u7c7b\u578b\u3002C# \u4e2d\u63d0\u4f9b\u7684\u57fa\u672c\u7684\u503c\u7c7b\u578b\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u51e0\u7c7b\uff1a \u7c7b\u578b \u4e3e\u4f8b \u6574\u6570\u7c7b\u578b sbyte […]<\/p>\n","protected":false},"author":321,"featured_media":234085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234082","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\/234082","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=234082"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234082\/revisions"}],"predecessor-version":[{"id":234149,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234082\/revisions\/234149"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/234085"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=234082"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=234082"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=234082"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}