{"id":245892,"date":"2022-07-06T09:17:49","date_gmt":"2022-07-06T01:17:49","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=245892"},"modified":"2022-06-23T18:18:17","modified_gmt":"2022-06-23T10:18:17","slug":"about-c-properties","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/about-c-properties.html","title":{"rendered":"\u4e86\u89e3\u4e0bC# \u5c5e\u6027\uff08Property\uff09"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u5c5e\u6027\uff08Property\uff09 \u662f\u7c7b\uff08class\uff09\u3001\u7ed3\u6784\uff08structure\uff09\u548c\u63a5\u53e3\uff08interface\uff09\u7684\u547d\u540d\uff08named\uff09\u6210\u5458\u3002\u7c7b\u6216\u7ed3\u6784\u4e2d\u7684\u6210\u5458\u53d8\u91cf\u6216\u65b9\u6cd5\u79f0\u4e3a \u57df\uff08Field\uff09\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n \u5c5e\u6027\uff08Property\uff09\u662f\u57df\uff08Field\uff09\u7684\u6269\u5c55\uff0c\u4e14\u53ef\u4f7f\u7528\u76f8\u540c\u7684\u8bed\u6cd5\u6765\u8bbf\u95ee\u3002\u5b83\u4eec\u4f7f\u7528 \u8bbf\u95ee\u5668\uff08accessors\uff09 \u8ba9\u79c1\u6709\u57df\u7684\u503c\u53ef\u88ab\u8bfb\u5199\u6216\u64cd\u4f5c\u3002<\/p>\n \u5c5e\u6027\uff08Property\uff09\u4e0d\u4f1a\u786e\u5b9a\u5b58\u50a8\u4f4d\u7f6e\u3002\u76f8\u53cd\uff0c\u5b83\u4eec\u5177\u6709\u53ef\u8bfb\u5199\u6216\u8ba1\u7b97\u5b83\u4eec\u503c\u7684 \u8bbf\u95ee\u5668\uff08accessors\uff09\u3002<\/p>\n \u4f8b\u5982\uff0c\u6709\u4e00\u4e2a\u540d\u4e3a Student \u7684\u7c7b\uff0c\u5e26\u6709 age\u3001name \u548c code \u7684\u79c1\u6709\u57df\u3002\u6211\u4eec\u4e0d\u80fd\u5728\u7c7b\u7684\u8303\u56f4\u4ee5\u5916\u76f4\u63a5\u8bbf\u95ee\u8fd9\u4e9b\u57df\uff0c\u4f46\u662f\u6211\u4eec\u53ef\u4ee5\u62e5\u6709\u8bbf\u95ee\u8fd9\u4e9b\u79c1\u6709\u57df\u7684\u5c5e\u6027\u3002<\/p>\n \u8bbf\u95ee\u5668\uff08Accessors\uff09<\/strong><\/div>\n \u5c5e\u6027\uff08Property\uff09\u7684\u8bbf\u95ee\u5668\uff08accessor\uff09\u5305\u542b\u6709\u52a9\u4e8e\u83b7\u53d6\uff08\u8bfb\u53d6\u6216\u8ba1\u7b97\uff09\u6216\u8bbe\u7f6e\uff08\u5199\u5165\uff09\u5c5e\u6027\u7684\u53ef\u6267\u884c\u8bed\u53e5\u3002\u8bbf\u95ee\u5668\uff08accessor\uff09\u58f0\u660e\u53ef\u5305\u542b\u4e00\u4e2a get \u8bbf\u95ee\u5668\u3001\u4e00\u4e2a set \u8bbf\u95ee\u5668\uff0c\u6216\u8005\u540c\u65f6\u5305\u542b\u4e8c\u8005\u3002\u4f8b\u5982\uff1a<\/p>\n \r\n\/\/ \u58f0\u660e\u7c7b\u578b\u4e3a string \u7684 Code \u5c5e\u6027\r\npublic<\/span> string<\/span> Code\r\n{\r\n get\r\n {\r\n return<\/span> code;\r\n }\r\n set\r\n {\r\n code =<\/span> value<\/span>;\r\n }\r\n}\r\n\/\/ \u58f0\u660e\u7c7b\u578b\u4e3a string \u7684 Name \u5c5e\u6027\r\npublic<\/span> string<\/span> Name\r\n{\r\n get\r\n {\r\n return<\/span> name;\r\n }\r\n set\r\n {\r\n name =<\/span> value<\/span>;\r\n }\r\n}\r\n\/\/ \u58f0\u660e\u7c7b\u578b\u4e3a int \u7684 Age \u5c5e\u6027>\r\npublic<\/span> int<\/span> Age\r\n{\r\n get\r\n {\r\n return<\/span> age;\r\n }\r\n set\r\n {\r\n age =<\/span> value<\/span>;\r\n }\r\n}<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/pre>\n |