{"id":44377,"date":"2025-06-18T17:17:39","date_gmt":"2025-06-18T09:17:39","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/44377.html"},"modified":"2025-06-18T17:17:39","modified_gmt":"2025-06-18T09:17:39","slug":"%e3%80%90c%e3%80%91-c%e4%b8%ad-nameof-%e5%92%8c-tostring-%e7%9a%84%e7%94%a8%e6%b3%95%e4%b8%8e%e5%8c%ba%e5%88%ab%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/44377.html","title":{"rendered":"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3"},"content":{"rendered":"<p>\u5728 C# \u7f16\u7a0b\u8fc7\u7a0b\u4e2d&#xff0c;nameof\u8fd0\u7b97\u7b26\u548cToString()\u65b9\u6cd5\u662f\u5f00\u53d1\u8005\u7ecf\u5e38\u4f1a\u7528\u5230\u7684\u529f\u80fd\u3002\u867d\u7136\u5b83\u4eec\u90fd\u80fd\u8fd4\u56de\u5b57\u7b26\u4e32&#xff0c;\u4f46\u5728\u5b9e\u9645\u4f7f\u7528\u573a\u666f\u3001\u5de5\u4f5c\u673a\u5236\u7b49\u65b9\u9762\u5b58\u5728\u660e\u663e\u5dee\u5f02\u3002\u672c\u6587\u5c06\u901a\u8fc7\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b&#xff0c;\u8be6\u7ec6\u4ecb\u7ecdnameof\u548c\u679a\u4e3e\u7ed3\u5408\u7684\u7528\u6cd5&#xff0c;\u4ee5\u53canameof\u4e0eToString()\u4e4b\u95f4\u7684\u533a\u522b\u3002<\/p>\n<p>&#x1f50d; \u4e00\u3001C# \u4e2d nameof \u52a0\u4e00\u4e2a\u679a\u4e3e\u7684\u542b\u4e49 nameof\u662f C# \u4e2d\u7684\u8fd0\u7b97\u7b26&#xff0c;\u5728\u7f16\u8bd1\u65f6\u83b7\u53d6\u53d8\u91cf\u3001\u7c7b\u578b\u6216\u8005\u6210\u5458\u7684\u540d\u79f0&#xff0c;\u5e76\u4ee5\u5b57\u7b26\u4e32\u5f62\u5f0f\u5448\u73b0\u3002\u5f53\u5b83\u4e0e\u679a\u4e3e\u7ed3\u5408\u4f7f\u7528\u65f6&#xff0c;\u8fd4\u56de\u7684\u662f\u679a\u4e3e\u6210\u5458\u7684\u540d\u79f0&#xff0c;\u800c\u975e\u8be5\u6210\u5458\u5bf9\u5e94\u7684\u503c \u3002 \u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u4e86\u5982\u4e0b\u679a\u4e3e\u7c7b\u578b&#xff1a;<\/p>\n<p><span class=\"token keyword\">enum<\/span> <span class=\"token class-name\">Color<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    Red<span class=\"token punctuation\">,<\/span><br \/>\n    Green<span class=\"token punctuation\">,<\/span><br \/>\n    Blue<br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801&#xff0c;\u53ef\u4ee5\u76f4\u89c2\u5730\u770b\u5230nameof\u4e0e\u679a\u4e3e\u7ed3\u5408\u4f7f\u7528\u7684\u6548\u679c&#xff1a;<\/p>\n<p><span class=\"token class-name\">Color<\/span> myColor <span class=\"token operator\">&#061;<\/span> Color<span class=\"token punctuation\">.<\/span>Green<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> name <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>myColor<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u5f97\u5230 &#034;myColor&#034;&#xff0c;\u4e5f\u5c31\u662f\u53d8\u91cf\u7684\u540d\u79f0<\/span><br \/>\n<span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> memberName <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>Color<span class=\"token punctuation\">.<\/span>Blue<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5f97\u5230 &#034;Blue&#034;&#xff0c;\u5373\u679a\u4e3e\u6210\u5458\u7684\u540d\u79f0<\/span><\/p>\n<p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;nameof\u4e0e\u679a\u4e3e\u7ed3\u5408\u5e38\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\u548c\u53c2\u6570\u9a8c\u8bc1\u3002\u6bd4\u5982\u5728\u65e5\u5fd7\u8bb0\u5f55\u65f6&#xff1a; Log($\u201c\u5f53\u524d\u989c\u8272: {nameof(Color.Red)}\u201d); \/\/ \u65e5\u5fd7\u4f1a\u663e\u793a \u201c\u5f53\u524d\u989c\u8272: Red\u201d<\/p>\n<p>\u5728\u53c2\u6570\u9a8c\u8bc1\u573a\u666f\u4e0b&#xff1a;<\/p>\n<p><span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">SetColor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Color<\/span> color<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>color <span class=\"token operator\">&#061;&#061;<\/span> Color<span class=\"token punctuation\">.<\/span>Red<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">ArgumentException<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u4e0d\u652f\u6301\u7ea2\u8272&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>color<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u53c2\u6570\u540d\u4f1a\u663e\u793a &#034;color&#034;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f&#xff0c;nameof(Color.Green) \u8fd9\u79cd\u5199\u6cd5&#xff0c;\u662f\u76f4\u63a5\u5f15\u7528\u679a\u4e3e\u7c7b\u578b\u4e2d\u7684\u6210\u5458&#xff0c;\u8fd4\u56de\u7684\u662f\u8be5\u6210\u5458\u5728\u4ee3\u7801\u91cc\u7684\u540d\u79f0&#xff1b;\u82e5\u60f3\u83b7\u53d6\u679a\u4e3e\u5b9e\u4f8b\u6240\u5bf9\u5e94\u7684\u6210\u5458\u540d\u79f0&#xff0c;\u53ef\u91c7\u7528 ToString() \u65b9\u6cd5&#xff0c;\u5982string colorName &#061; myColor.ToString(); &#xff0c;\u6b64\u65f6\u5f97\u5230\u7684\u7ed3\u679c\u662f \u201cGreen\u201d \u3002<\/p>\n<p>&#x1f504; \u4e8c\u3001nameof () \u548c ToString () \u7684\u533a\u522b<\/p>\n<li>&#x1f52d; \u529f\u80fd\u4e0d\u540c nameof&#xff1a;\u5728\u7f16\u8bd1\u65f6\u83b7\u53d6\u4ee3\u7801\u4e2d\u53d8\u91cf\u3001\u7c7b\u578b\u6216\u6210\u5458\u7684\u540d\u79f0&#xff08;\u5373\u6e90\u4ee3\u7801\u4e2d\u7684\u6807\u8bc6\u7b26&#xff09;\u3002 ToString()&#xff1a;\u5728\u8fd0\u884c\u65f6\u8fd4\u56de\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\u8868\u793a\u5f62\u5f0f&#xff08;\u901a\u5e38\u662f\u5bf9\u8c61\u7684\u503c\u6216\u81ea\u5b9a\u4e49\u683c\u5f0f&#xff09;\u3002<\/li>\n<li>&#x1f4ca; \u8fd4\u56de\u503c\u4e0d\u540c \u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b&#xff0c;\u53ef\u4ee5\u6e05\u6670\u770b\u5230\u4e8c\u8005\u8fd4\u56de\u503c\u7684\u5dee\u5f02&#xff1a;<\/li>\n<p><span class=\"token keyword\">enum<\/span> <span class=\"token class-name\">Color<\/span> <span class=\"token punctuation\">{<\/span> Red<span class=\"token punctuation\">,<\/span> Green<span class=\"token punctuation\">,<\/span> Blue <span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token class-name\">Color<\/span> myColor <span class=\"token operator\">&#061;<\/span> Color<span class=\"token punctuation\">.<\/span>Green<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> a <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>myColor<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ \u8fd4\u56de\u53d8\u91cf\u540d&#xff1a;&#034;myColor&#034;<\/span><br \/>\n<span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>Color<span class=\"token punctuation\">.<\/span>Blue<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u8fd4\u56de\u679a\u4e3e\u6210\u5458\u540d&#xff1a;&#034;Blue&#034;<\/span><br \/>\n<span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> c <span class=\"token operator\">&#061;<\/span> myColor<span class=\"token punctuation\">.<\/span><span class=\"token function\">ToString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u8fd4\u56de\u679a\u4e3e\u503c\u7684\u540d\u79f0&#xff1a;&#034;Green&#034;<\/span><br \/>\n<span class=\"token class-name\"><span class=\"token keyword\">string<\/span><\/span> d <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">42<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">ToString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u8fd4\u56de\u6570\u503c\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f&#xff1a;&#034;42&#034;<\/span><\/p>\n<p>\u53ef\u4ee5\u603b\u7ed3\u6210\u5982\u4e0b\u8868\u683c&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250618091738-685284321cbad.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<li>&#x1f4cc; \u5e94\u7528\u573a\u666f\u4e0d\u540c nameof \u7684\u5178\u578b\u573a\u666f \u53c2\u6570\u9a8c\u8bc1&#xff08;\u5728\u5f02\u5e38\u4e2d\u663e\u793a\u53c2\u6570\u540d&#xff09;&#xff1a;<\/li>\n<p><span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">SetColor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Color<\/span> color<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>color <span class=\"token operator\">&#061;&#061;<\/span> Color<span class=\"token punctuation\">.<\/span>Red<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">ArgumentException<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u65e0\u6548\u989c\u8272&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">nameof<\/span><span class=\"token punctuation\">(<\/span>color<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u663e\u793a\u53c2\u6570\u540d &#034;color&#034;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u65e5\u5fd7\u8bb0\u5f55 \/ \u8c03\u8bd5&#xff08;\u8bb0\u5f55\u4ee3\u7801\u5143\u7d20\u540d\u79f0&#xff09;&#xff1a; Log($\u201c\u521d\u59cb\u5316 {nameof(Color)} \u679a\u4e3e\u201d); \/\/ \u65e5\u5fd7&#xff1a;\u201c\u521d\u59cb\u5316 Color \u679a\u4e3e\u201d<\/p>\n<p>ToString() \u7684\u5178\u578b\u573a\u666f \u83b7\u53d6\u5bf9\u8c61\u503c\u7684\u6587\u672c\u8868\u793a&#xff1a; Console.WriteLine(myColor.ToString()); \/\/ \u8f93\u51fa&#xff1a;\u201cGreen\u201d<\/p>\n<p>\u81ea\u5b9a\u4e49\u683c\u5f0f\u5316&#xff08;\u91cd\u5199 ToString() \u65b9\u6cd5&#xff09;&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Person<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">string<\/span><\/span> Name <span class=\"token punctuation\">{<\/span> <span class=\"token keyword\">get<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">set<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">override<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">string<\/span><\/span> <span class=\"token function\">ToString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token interpolation-string\"><span class=\"token string\">$&#034;Person: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token expression language-csharp\">Name<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token class-name\"><span class=\"token keyword\">var<\/span><\/span> person <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">Person<\/span> <span class=\"token punctuation\">{<\/span> Name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;Alice&#034;<\/span> <span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\nConsole<span class=\"token punctuation\">.<\/span><span class=\"token function\">WriteLine<\/span><span class=\"token punctuation\">(<\/span>person<span class=\"token punctuation\">.<\/span><span class=\"token function\">ToString<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8f93\u51fa&#xff1a;&#034;Person: Alice&#034;<\/span><\/p>\n<li>\u2699\ufe0f \u6280\u672f\u7ec6\u8282\u5dee\u5f02 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250618091738-685284322e114.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> &#x1f31f; \u603b\u7ed3 \u5728 C# \u7f16\u7a0b\u4e2d&#xff0c;nameof\u548cToString()\u6709\u7740\u5404\u81ea\u72ec\u7279\u7684\u4f5c\u7528\u3002nameof\u5e38\u7528\u4e8e\u83b7\u53d6\u4ee3\u7801\u4e2d\u7684\u5143\u7d20\u540d\u79f0&#xff0c;\u5982\u53d8\u91cf\u540d\u3001\u7c7b\u578b\u540d\u3001\u5c5e\u6027\u540d&#xff1b;\u800cToString()\u5219\u4fa7\u91cd\u4e8e\u83b7\u53d6\u5bf9\u8c61\u503c\u6216\u5185\u5bb9\u7684\u5b57\u7b26\u4e32\u8868\u793a\u3002\u7406\u89e3\u5e76\u6b63\u786e\u4f7f\u7528\u8fd9\u4e24\u4e2a\u529f\u80fd&#xff0c;\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u7f16\u5199\u51fa\u66f4\u6e05\u6670\u3001\u5065\u58ee\u7684\u4ee3\u7801\u3002\u5982\u679c\u4f60\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u8fd8\u6709\u5176\u4ed6\u5173\u4e8e C# \u7684\u7591\u95ee&#xff0c;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u5206\u4eab\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb168\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u5bf9\u6bd4\u4e86C#\u4e2dnameof\u8fd0\u7b97\u7b26\u548cToString()\u65b9\u6cd5\u7684\u533a\u522b\u3002nameof\u5728\u7f16\u8bd1\u65f6\u83b7\u53d6\u4ee3\u7801\u5143\u7d20\u540d\u79f0\uff0c\u9002\u7528\u4e8e\u53c2\u6570\u9a8c\u8bc1\uff08\u5982\u663e\u793a\u5f02\u5e38\u53c2\u6570\u540d\uff09\u548c\u65e5\u5fd7\u8bb0\u5f55\uff08\u8bb0\u5f55\u53d8\u91cf\/\u7c7b\u578b\u540d\uff09\uff1b\u800cToString()\u5728\u8fd0\u884c\u65f6\u8fd4\u56de\u5bf9\u8c61\u503c\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5e38\u7528\u4e8e\u8f93\u51fa\u679a\u4e3e\u503c\u6216\u81ea\u5b9a\u4e49\u5bf9\u8c61\u683c\u5f0f\u3002\u901a\u8fc7\u679a\u4e3e\u793a\u4f8b\u5c55\u793a\u4e86\u4e24\u79cd\u65b9\u6cd5\u7684\u5dee\u5f02\uff1anameof(Color.Blue)\u8fd4\u56de&quot;Blue&quot;\uff08\u6210\u5458\u540d\uff09\uff0c\u800cColor.Green.ToString()\u8fd4\u56de&quot;Green&quot;\uff08\u503c\u540d\uff09\u3002\u5f00\u53d1\u8005\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u4f7f\u7528\uff1a\u9700\u8981\u4ee3\u7801\u5143<\/p>\n","protected":false},"author":2,"featured_media":44375,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[84,4137,55,99],"topic":[],"class_list":{"0":"post-44377","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","6":"hentry","7":"category-server","8":"tag-android","9":"tag-c","11":"tag-java"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/44377.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb168\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u5bf9\u6bd4\u4e86C#\u4e2dnameof\u8fd0\u7b97\u7b26\u548cToString()\u65b9\u6cd5\u7684\u533a\u522b\u3002nameof\u5728\u7f16\u8bd1\u65f6\u83b7\u53d6\u4ee3\u7801\u5143\u7d20\u540d\u79f0\uff0c\u9002\u7528\u4e8e\u53c2\u6570\u9a8c\u8bc1\uff08\u5982\u663e\u793a\u5f02\u5e38\u53c2\u6570\u540d\uff09\u548c\u65e5\u5fd7\u8bb0\u5f55\uff08\u8bb0\u5f55\u53d8\u91cf\/\u7c7b\u578b\u540d\uff09\uff1b\u800cToString()\u5728\u8fd0\u884c\u65f6\u8fd4\u56de\u5bf9\u8c61\u503c\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5e38\u7528\u4e8e\u8f93\u51fa\u679a\u4e3e\u503c\u6216\u81ea\u5b9a\u4e49\u5bf9\u8c61\u683c\u5f0f\u3002\u901a\u8fc7\u679a\u4e3e\u793a\u4f8b\u5c55\u793a\u4e86\u4e24\u79cd\u65b9\u6cd5\u7684\u5dee\u5f02\uff1anameof(Color.Blue)\u8fd4\u56de&quot;Blue&quot;\uff08\u6210\u5458\u540d\uff09\uff0c\u800cColor.Green.ToString()\u8fd4\u56de&quot;Green&quot;\uff08\u503c\u540d\uff09\u3002\u5f00\u53d1\u8005\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u4f7f\u7528\uff1a\u9700\u8981\u4ee3\u7801\u5143\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/44377.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-06-18T09:17:39+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250618091738-685284321cbad.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44377.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/44377.html\",\"name\":\"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-06-18T09:17:39+00:00\",\"dateModified\":\"2025-06-18T09:17:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/44377.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/44377.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/44377.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/44377.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb168\u6b21\uff0c\u70b9\u8d5e4\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u672c\u6587\u5bf9\u6bd4\u4e86C#\u4e2dnameof\u8fd0\u7b97\u7b26\u548cToString()\u65b9\u6cd5\u7684\u533a\u522b\u3002nameof\u5728\u7f16\u8bd1\u65f6\u83b7\u53d6\u4ee3\u7801\u5143\u7d20\u540d\u79f0\uff0c\u9002\u7528\u4e8e\u53c2\u6570\u9a8c\u8bc1\uff08\u5982\u663e\u793a\u5f02\u5e38\u53c2\u6570\u540d\uff09\u548c\u65e5\u5fd7\u8bb0\u5f55\uff08\u8bb0\u5f55\u53d8\u91cf\/\u7c7b\u578b\u540d\uff09\uff1b\u800cToString()\u5728\u8fd0\u884c\u65f6\u8fd4\u56de\u5bf9\u8c61\u503c\u7684\u5b57\u7b26\u4e32\u8868\u793a\uff0c\u5e38\u7528\u4e8e\u8f93\u51fa\u679a\u4e3e\u503c\u6216\u81ea\u5b9a\u4e49\u5bf9\u8c61\u683c\u5f0f\u3002\u901a\u8fc7\u679a\u4e3e\u793a\u4f8b\u5c55\u793a\u4e86\u4e24\u79cd\u65b9\u6cd5\u7684\u5dee\u5f02\uff1anameof(Color.Blue)\u8fd4\u56de&quot;Blue&quot;\uff08\u6210\u5458\u540d\uff09\uff0c\u800cColor.Green.ToString()\u8fd4\u56de&quot;Green&quot;\uff08\u503c\u540d\uff09\u3002\u5f00\u53d1\u8005\u5e94\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u4f7f\u7528\uff1a\u9700\u8981\u4ee3\u7801\u5143","og_url":"https:\/\/www.wsisp.com\/helps\/44377.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-06-18T09:17:39+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/06\/20250618091738-685284321cbad.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/44377.html","url":"https:\/\/www.wsisp.com\/helps\/44377.html","name":"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-06-18T09:17:39+00:00","dateModified":"2025-06-18T09:17:39+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/44377.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/44377.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/44377.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010C#\u3011 C#\u4e2d nameof \u548c ToString () \u7684\u7528\u6cd5\u4e0e\u533a\u522b\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=44377"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/44377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/44375"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=44377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=44377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=44377"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=44377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}