{"id":63433,"date":"2023-11-25T11:35:54","date_gmt":"2023-11-25T03:35:54","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=63433"},"modified":"2023-11-25T11:36:07","modified_gmt":"2023-11-25T03:36:07","slug":"c-%e4%b8%ad%e7%9a%84-new-%e5%92%8c-c%e4%b8%ad%e7%9a%84-new-%e6%9c%89%e4%bb%80%e4%b9%88%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/63433.html","title":{"rendered":"C# \u4e2d\u7684 new \u548c C\u4e2d\u7684 new \u6709\u4ec0\u4e48\u533a\u522b"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>C#\u548cC\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u4eec\u5728\u5f88\u591a\u65b9\u9762\u6709\u7740\u663e\u8457\u7684\u5dee\u5f02\uff0c\u5c24\u5176\u662f\u5728\u5173\u952e\u5b57\u201cnew\u201d\u7684\u4f7f\u7528\u548c\u610f\u4e49\u4e0a\u3002\u867d\u7136\u4e24\u8005\u90fd\u4f7f\u7528\u4e86\u201cnew\u201d\u8fd9\u4e2a\u5173\u952e\u5b57\uff0c\u4f46\u5b83\u4eec\u5728\u8bed\u4e49\u3001\u529f\u80fd\u548c\u5e94\u7528\u573a\u666f\u4e0a\u6709\u7740\u6839\u672c\u7684\u4e0d\u540c\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8C#\u4e2d\u7684new\u548cC\u4e2d\u7684new\u7684\u4e3b\u8981\u533a\u522b\uff0c\u5305\u62ec\uff1a1.\u8bed\u8a00\u7c7b\u578b\u548c\u7f16\u7a0b\u8303\u5f0f\u7684\u5dee\u5f02\uff1b2.new\u5728\u4e24\u79cd\u8bed\u8a00\u4e2d\u7684\u8bed\u4e49\u548c\u7528\u9014\uff1b3.\u5185\u5b58\u7ba1\u7406\u548c\u5783\u573e\u56de\u6536\u673a\u5236\u7684\u5bf9\u6bd4\uff1b4.\u9762\u5411\u5bf9\u8c61\u7279\u6027\u548c\u6570\u636e\u7c7b\u578b\u5904\u7406\u7684\u4e0d\u540c\uff1b5.\u5f00\u53d1\u73af\u5883\u548c\u5e94\u7528\u9886\u57df\u7684\u533a\u522b\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u9762\u7684\u6bd4\u8f83\uff0c\u8bfb\u8005\u53ef\u4ee5\u66f4\u6e05\u6670\u5730\u7406\u89e3C#\u548cC\u5728\u4f7f\u7528new\u5173\u952e\u5b57\u65f6\u7684\u4e0d\u540c\u8003\u8651\u548c\u5b9e\u73b0\u65b9\u5f0f\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1.<\/strong><strong>\u8bed\u8a00\u7c7b\u578b\u548c\u7f16\u7a0b\u8303\u5f0f\u7684\u5dee\u5f02<\/strong><\/h2>\n\n\n\n<p>C#\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u3001\u7c7b\u578b\u5b89\u5168\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u652f\u6301\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\uff0c\u800cC\u662f\u4e00\u79cd\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\u8bed\u8a00\uff0c\u9700\u8981\u624b\u52a8\u7ba1\u7406\u5185\u5b58\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2.new<\/strong><strong>\u5728\u4e24\u79cd\u8bed\u8a00\u4e2d\u7684\u8bed\u4e49\u548c\u7528\u9014<\/strong><\/h2>\n\n\n\n<p>\u5728C#\u4e2d\uff0cnew\u5173\u952e\u5b57\u7528\u4e8e\u521b\u5efa\u5bf9\u8c61\u7684\u5b9e\u4f8b\uff0c\u5e76\u81ea\u52a8\u5206\u914d\u548c\u7ba1\u7406\u5185\u5b58\u3002\u800c\u5728C\u4e2d\uff0cnew\u4e3b\u8981\u7528\u4e8e\u52a8\u6001\u5185\u5b58\u5206\u914d\uff0c\u9700\u624b\u52a8\u7ba1\u7406\u5185\u5b58\u7684\u5206\u914d\u548c\u91ca\u653e\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3.<\/strong><strong>\u5185\u5b58\u7ba1\u7406\u548c\u5783\u573e\u56de\u6536\u673a\u5236\u7684\u5bf9\u6bd4<\/strong><\/h2>\n\n\n\n<p>C#\u5177\u6709\u81ea\u52a8\u5783\u573e\u56de\u6536\u673a\u5236\uff0c\u53ef\u4ee5\u81ea\u52a8\u7ba1\u7406\u548c\u56de\u6536\u4e0d\u518d\u4f7f\u7528\u7684\u5185\u5b58\u3002\u800cC\u8bed\u8a00\u4e2d\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u624b\u52a8\u91ca\u653e\u5206\u914d\u7684\u5185\u5b58\uff0c\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4.<\/strong><strong>\u9762\u5411\u5bf9\u8c61\u7279\u6027\u548c\u6570\u636e\u7c7b\u578b\u5904\u7406\u7684\u4e0d\u540c<\/strong><\/h2>\n\n\n\n<p>C#\u4f5c\u4e3a\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u8a00\uff0c\u652f\u6301\u7c7b\u548c\u5bf9\u8c61\u7684\u6982\u5ff5\uff0cnew\u5173\u952e\u5b57\u7528\u4e8e\u5b9e\u4f8b\u5316\u7c7b\u3002\u800cC\u4f5c\u4e3a\u8fc7\u7a0b\u5f0f\u8bed\u8a00\uff0c\u4e0d\u652f\u6301\u7c7b\u548c\u5bf9\u8c61\uff0cnew\u7528\u4e8e\u5206\u914d\u4efb\u610f\u7c7b\u578b\u7684\u5185\u5b58\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5.<\/strong><strong>\u5f00\u53d1\u73af\u5883\u548c\u5e94\u7528\u9886\u57df\u7684\u533a\u522b<\/strong><\/h2>\n\n\n\n<p>C#\u901a\u5e38\u7528\u4e8e.NET\u5e73\u53f0\u7684\u5e94\u7528\u5f00\u53d1\uff0c\u5305\u62ec\u684c\u9762\u3001Web\u548c\u79fb\u52a8\u5e94\u7528\u3002\u800cC\u8bed\u8a00\u66f4\u591a\u7528\u4e8e\u7cfb\u7edf\u7f16\u7a0b\u3001\u5d4c\u5165\u5f0f\u5f00\u53d1\u7b49\u9886\u57df\u3002<\/p>\n\n\n\n<p><img fetchpriority=\"high\" decoding=\"async\" width=\"484\" height=\"300\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/11\/799100-C\u4e2d\u7684new\u548cC\u4e2d\u7684new\u6709\u4ec0\u4e48\u533a\u522b.png?x-oss-process=image\/auto-orient,1\/format,webp\" class=\"aligncenter\" alt=\"C# \u4e2d\u7684 new \u548c C\u4e2d\u7684 new \u6709\u4ec0\u4e48\u533a\u522b\" \/><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u7b54<\/strong><\/h2>\n\n\n\n<p><strong>1.C#<\/strong><strong>\u548cC\u5728\u4f7f\u7528new\u5173\u952e\u5b57\u65f6\u4e3b\u8981\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><\/p>\n\n\n\n<p>\u5728C#\u4e2d\uff0cnew\u5173\u952e\u5b57\u7528\u4e8e\u521b\u5efa\u7c7b\u7684\u5bf9\u8c61\u5b9e\u4f8b\uff0c\u5b83\u6d89\u53ca\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u81ea\u52a8\u5904\u7406\u5185\u5b58\u5206\u914d\u548c\u5783\u573e\u56de\u6536\u3002\u800c\u5728C\u4e2d\uff0cnew\u4e3b\u8981\u7528\u4e8e\u52a8\u6001\u5185\u5b58\u5206\u914d\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u624b\u52a8\u7ba1\u7406\u5185\u5b58\u7684\u5206\u914d\u548c\u91ca\u653e\uff0c\u901a\u5e38\u4e0emalloc\u51fd\u6570\u7ed3\u5408\u4f7f\u7528\u3002<\/p>\n\n\n\n<p><strong>2.C#<\/strong><strong>\u4e2d\u7684new\u5173\u952e\u5b57\u5728\u5185\u5b58\u7ba1\u7406\u65b9\u9762\u5982\u4f55\u5de5\u4f5c\uff1f<\/strong><\/p>\n\n\n\n<p>\u5728C#\u4e2d\uff0c\u5f53\u4f7f\u7528new\u5173\u952e\u5b57\u521b\u5efa\u5bf9\u8c61\u65f6\uff0c\u5b83\u81ea\u52a8\u5728\u6258\u7ba1\u5806\u4e0a\u5206\u914d\u5185\u5b58\uff0c\u5e76\u7531.NET\u6846\u67b6\u7684\u5783\u573e\u56de\u6536\u673a\u5236\u8d1f\u8d23\u7ba1\u7406\u8fd9\u4e9b\u5185\u5b58\u3002\u8fd9\u610f\u5473\u7740\u7a0b\u5e8f\u5458\u4e0d\u9700\u8981\u624b\u52a8\u91ca\u653e\u5185\u5b58\uff0c\u51cf\u5c11\u4e86\u5185\u5b58\u6cc4\u6f0f\u7684\u98ce\u9669\u3002<\/p>\n\n\n\n<p><strong>3.<\/strong><strong>\u4e3a\u4ec0\u4e48\u8bf4C\u4e2d\u7684new\u5173\u952e\u5b57\u4f7f\u7528\u66f4\u52a0\u590d\u6742\uff1f<\/strong><\/p>\n\n\n\n<p>\u5728C\u8bed\u8a00\u4e2d\uff0c\u4f7f\u7528new\u5173\u952e\u5b57\uff08\u6216\u66f4\u5e38\u89c1\u7684malloc\u51fd\u6570\uff09\u5206\u914d\u5185\u5b58\u65f6\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u81ea\u5df1\u8d1f\u8d23\u7ba1\u7406\u8fd9\u4e9b\u5185\u5b58\u3002\u8fd9\u5305\u62ec\u6b63\u786e\u5206\u914d\u6240\u9700\u5927\u5c0f\u7684\u5185\u5b58\uff0c\u4ee5\u53ca\u5728\u4e0d\u518d\u9700\u8981\u65f6\u9002\u65f6\u91ca\u653e\u5185\u5b58\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u76f8\u5bf9\u590d\u6742\uff0c\u5bb9\u6613\u51fa\u73b0\u5185\u5b58\u6cc4\u6f0f\u6216\u5176\u4ed6\u5185\u5b58\u7ba1\u7406\u9519\u8bef\u3002<\/p>\n\n\n\n<p><strong>4.C#<\/strong><strong>\u7684new\u548cC\u7684new\u5728\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u65b9\u9762\u6709\u4f55\u4e0d\u540c\uff1f<\/strong><\/p>\n\n\n\n<p>C#\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5176new\u5173\u952e\u5b57\u7528\u4e8e\u5b9e\u4f8b\u5316\u7c7b\uff0c\u652f\u6301\u5c01\u88c5\u3001\u7ee7\u627f\u548c\u591a\u6001\u7b49\u9762\u5411\u5bf9\u8c61\u7279\u6027\u3002\u800cC\u662f\u4e00\u79cd\u8fc7\u7a0b\u5f0f\u8bed\u8a00\uff0c\u4e0d\u652f\u6301\u4f20\u7edf\u610f\u4e49\u4e0a\u7684\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u5176new\u5173\u952e\u5b57\u4e3b\u8981\u7528\u4e8e\u5185\u5b58\u5206\u914d\uff0c\u800c\u4e0d\u6d89\u53ca\u5bf9\u8c61\u548c\u7c7b\u7684\u6982\u5ff5\u3002<\/p>\n\n\n\n<p><strong>5.<\/strong><strong>\u8fd9\u4e24\u79cd\u8bed\u8a00\u7684new\u5173\u952e\u5b57\u5728\u5e94\u7528\u9886\u57df\u6709\u4ec0\u4e48\u4e0d\u540c\u7684\u5f71\u54cd\uff1f<\/strong><\/p>\n\n\n\n<p>C#\u7684new\u5173\u952e\u5b57\u4f7f\u5176\u5728.NET\u5e73\u53f0\u4e0b\u7684\u684c\u9762\u3001Web\u548c\u79fb\u52a8\u5e94\u7528\u5f00\u53d1\u4e2d\u66f4\u4e3a\u9ad8\u6548\u548c\u5b89\u5168\uff0c\u7279\u522b\u662f\u5728\u9700\u8981\u5feb\u901f\u5f00\u53d1\u548c\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\u7684\u5e94\u7528\u4e2d\u3002\u800cC\u8bed\u8a00\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u5f0f\u4f7f\u5176\u5728\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u5185\u5b58\u548c\u7cfb\u7edf\u7ea7\u7f16\u7a0b\u7684\u5e94\u7528\u4e2d\uff0c\u5982\u5d4c\u5165\u5f0f\u7cfb\u7edf\u548c\u64cd\u4f5c\u7cfb\u7edf\u5f00\u53d1\uff0c\u66f4\u4e3a\u5408\u9002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"C#\u548cC\u662f\u4e24\u79cd\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u4eec\u5728\u5f88\u591a\u65b9\u9762\u6709\u7740\u663e\u8457\u7684\u5dee\u5f02\uff0c\u5c24\u5176\u662f\u5728\u5173\u952e\u5b57\u201cnew\u201d\u7684\u4f7f\u7528\u548c\u610f\u4e49\u4e0a\u3002\u867d\u7136\u4e24\u8005\u90fd [&hellip;]","protected":false},"author":5,"featured_media":63438,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/63433"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=63433"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/63433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/63438"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=63433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=63433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=63433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}