{"id":772,"date":"2024-07-23T01:05:04","date_gmt":"2024-07-23T08:05:04","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=772"},"modified":"2024-07-23T01:08:57","modified_gmt":"2024-07-23T08:08:57","slug":"c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/","title":{"rendered":"C# 13\uff1a\u63a2\u7d22\u6700\u65b0\u7684\u9884\u89c8\u529f\u80fd\u00a0"},"content":{"rendered":"<p style=\"text-align: center;\"><em>\u672c\u7bc7\u7ffb\u8bd1\u4e8eKathleen Dollard\u00a0\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/csharp-13-explore-preview-features\/\">C# 13: Explore the latest preview features &#8211; .NET Blog (microsoft.com)<\/a>\u00a0<\/em><\/p>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5df2\u521d\u5177\u96cf\u5f62<\/span><span data-contrast=\"auto\">\uff0c<\/span><span data-contrast=\"auto\">\u5176\u65b0\u7279\u6027\u4fa7\u91cd\u4e8e\u7075\u6d3b\u6027\u3001\u6027\u80fd\u4ee5\u53ca\u4f7f\u60a8\u6700\u559c\u6b22\u7684\u529f\u80fd\u5728\u65e5\u5e38\u4e2d\u53d8\u5f97\u66f4\u5bb9\u6613\u4f7f\u7528\u3002\u6211\u4eec\u4ee5<\/span><a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/Language%20Feature%20Status.md\"><span data-contrast=\"none\">\u516c\u5f00\u7684\u65b9\u5f0f<\/span><\/a><span data-contrast=\"auto\">\u6784\u5efa<\/span><span data-contrast=\"auto\"> C#<\/span><span data-contrast=\"auto\">\uff0c\u5728\u4eca\u5e74\u7684<\/span> <a href=\"https:\/\/www.youtube.com\/watch?v=O3hx6oPWzX8&amp;t=9s\"><span data-contrast=\"auto\">Microsoft Build <\/span><span data-contrast=\"none\">\u5927\u4f1a<\/span><\/a><span data-contrast=\"auto\">\u4e0a\uff0c\u6211\u4eec\u4f1a\u8ba9\u60a8\u4e00\u7779<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u7684\u7cbe\u5f69\u4e4b\u5904\u3002\u4eca\u5929\uff0c\u6211\u4eec\u60f3\u5206\u4eab\u4e00\u4e0b<\/span><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5f53\u524d\u7684\u72b6\u6001\uff0c\u4ee5\u53ca\u60a8\u4eca\u5929\u5c31\u53ef\u4ee5\u5c1d\u8bd5\u7684\u65b0\u529f\u80fd\uff0c\u5e76\u63d0\u4f9b\u6709\u5173\u6b64\u7248\u672c\u53ca\u4ee5\u540e\u8ba1\u5212\u4e2d\u7684\u529f\u80fd\u66f4\u65b0\u3002\u8ba9\u6211\u4eec\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3\u8fd9\u4e9b\u65b0\u529f\u80fd\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#params%e9%9b%86%e5%90%88\">\u589e\u5f3a\u4e86 params \u96c6\u5408\u4ee5\u5b9e\u73b0\u66f4\u5f3a\u7684\u7075\u6d3b\u6027<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#lock%e5%af%b9%e8%b1%a1\">lock\u5bf9\u8c61<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#%e4%bb%8e%e5%88%9d%e5%a7%8b%e5%8c%96%e5%99%a8%e6%9c%ab%e5%b0%be%e5%bc%80%e5%a7%8b%e7%9a%84%e7%b4%a2%e5%bc%95\">\u7d22\u5f15\u8fd0\u7b97\u7b26\u6539\u8fdb<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"4\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#%e8%bd%ac%e4%b9%89%e5%ba%8f%e5%88%97-e\">\u8f6c\u4e49\u5e8f\u5217 \\e<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"5\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#partial%e5%b1%9e%e6%80%a7\">Partial\u5c5e\u6027<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"6\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#%e6%96%b9%e6%b3%95%e7%bb%84%e8%87%aa%e7%84%b6%e7%b1%bb%e5%9e%8b%e6%94%b9%e8%bf%9b\">\u65b9\u6cd5\u7ec4\u81ea\u7136\u7c7b\u578b\u6539\u8fdb<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"7\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#async%e6%96%b9%e6%b3%95%e5%92%8c%e8%bf%ad%e4%bb%a3%e5%99%a8%e4%b8%ad%e7%9a%84-ref-%e5%92%8c-unsafe\">async\u65b9\u6cd5\u548c\u8fed\u4ee3\u5668\u4e2d\u7684 ref \u548c unsafe<\/a><\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:860,&quot;335559991&quot;:440,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"8\" data-aria-level=\"1\"><a href=\"https:\/\/devblogs.microsoft.com\/dotnet-ch\/c-13%ef%bc%9a%e6%8e%a2%e7%b4%a2%e6%9c%80%e6%96%b0%e7%9a%84%e9%a2%84%e8%a7%88%e5%8a%9f%e8%83%bd\/#%e7%ab%8b%e5%8d%b3%e8%af%95%e7%94%a8-c-13#%e6%89%a9%e5%b1%95%e7%b1%bb%e5%9e%8b%e7%9a%84%e6%9b%b4%e6%96%b0\">\u6269\u5c55\u7c7b\u578b\u66f4\u65b0<\/a><\/li>\n<\/ul>\n<h3><b><span data-contrast=\"auto\">\u7acb\u5373\u8bd5\u7528<\/span><\/b><b><span data-contrast=\"auto\"> C# 13<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u5728\u6211\u4eec\u6df1\u5165\u7814\u7a76<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u7684\u6bcf\u4e2a\u65b0\u529f\u80fd\u4e4b\u524d\uff0c\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\u5982\u4f55\u4f7f\u7528\u5b83\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u60a8\u53ef\u4ee5\u5728\u6700\u65b0\u7684<\/span> <a href=\"https:\/\/dotnet.microsoft.com\/en-us\/download\/dotnet\/9.0\"><span data-contrast=\"auto\">.NET 9 <\/span><span data-contrast=\"none\">\u9884\u89c8\u7248<\/span><\/a><span data-contrast=\"auto\">\uff08\u64b0\u5199\u672c\u6587\u65f6\u4e3a\u9884\u89c8\u7248<\/span><span data-contrast=\"auto\"> 6<\/span><span data-contrast=\"auto\">\uff09\u548c<\/span> <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\"><span data-contrast=\"none\">Visual Studio 2022-17.11<\/span><\/a> <span data-contrast=\"auto\">\u7684\u6700\u65b0\u9884\u89c8\u7248\u4e2d\u627e\u5230<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u7684\u6700\u65b0\u9884\u89c8\u7248\u3002\u82e5\u8981\u8bbf\u95ee\u9884\u89c8\u529f\u80fd\uff0c\u8bf7\u5728\u9879\u76ee\u6587\u4ef6\u4e2d\u5c06\u60a8\u7684\u8bed\u8a00\u7248\u672c\u8bbe\u7f6e\u4e3a<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">preview<\/span>\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">&lt;Project Sdk=\"Microsoft.NET.Sdk\"&gt;\r\n   &lt;PropertyGroup&gt;\r\n      &lt;!--other settings--&gt;\r\n      &lt;LangVersion&gt;preview&lt;\/LangVersion&gt;\r\n      &lt;!--other settings--&gt;\r\n   &lt;\/PropertyGroup&gt;\r\n&lt;\/Project&gt;<\/code><\/pre>\n<h3><span style=\"color: #ff0000;\"><b>params<\/b><\/span><b><span data-contrast=\"auto\">\u96c6\u5408<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">C# 13<\/span><span data-contrast=\"auto\">\u6269\u5c55\u4e86<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">\u202fparams<\/span><span data-contrast=\"auto\">\u5173\u952e\u5b57\uff0c\u4f7f\u5176\u9002\u7528\u4e8e\u53ef\u4ee5\u901a\u8fc7\u96c6\u5408\u8868\u8fbe\u5f0f\u6784\u9020\u7684\u4efb\u4f55\u7c7b\u578b\u3002\u65e0\u8bba\u662f\u7f16\u5199\u65b9\u6cd5\u8fd8\u662f\u8c03\u7528\u65b9\u6cd5\uff0c\u90fd\u589e\u52a0\u4e86\u7075\u6d3b\u6027<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5f53<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> params<\/span> <\/span><span data-contrast=\"auto\">\u5173\u952e\u5b57\u51fa\u73b0\u5728\u53c2\u6570\u4e4b\u524d\u65f6\uff0c\u5bf9\u8be5\u65b9\u6cd5\u7684\u8c03\u7528\u53ef\u4ee5\u63d0\u4f9b\u96f6\u4e2a\u6216\u591a\u4e2a\u503c\u7684\u9017\u53f7\u5206\u9694\u5217\u8868\u3002\u4ee5\u4e0b\u5185\u5bb9\u9002\u7528\u4e8e\u6240\u6709\u7248\u672c\u7684<\/span><span data-contrast=\"auto\"> C#\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public void WriteNames(params string[] names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));\r\n\r\nWriteNames(\"Mads\", \"Dustin\", \"Kathleen\");\r\nWriteNames(new string[] {\"Mads\", \"Dustin\", \"Kathleen\"});\r\n\/\/ Both of these Would output: Mads, Dustin, Kathleen<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u8bf7\u6ce8\u610f\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u5206\u9694\u7684\u503c\u5217\u8868\u6216\u57fa\u7840\u7c7b\u578b\u7684\u5bf9\u8c61\u6765\u8c03\u7528\u8be5\u65b9\u6cd5\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u4ece<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u5f00\u59cb\uff0c<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">params<\/span> <\/span><span data-contrast=\"auto\">\u53c2\u6570\u53ef\u4ee5\u662f\u96c6\u5408\u8868\u8fbe\u5f0f\u652f\u6301\u7684\u4efb\u4f55\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public void WriteNames(params List&lt;string&gt; names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u6bcf\u5f53\u8c03\u7528\u5177\u6709<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> IEnumerable&lt;T&gt; <\/span><span data-contrast=\"auto\">\u53c2\u6570\u7684\u65b9\u6cd5\u65f6\uff0c\u90fd\u53ef\u4ee5\u4f20\u9012<\/span><span data-contrast=\"auto\"> LINQ <\/span><span data-contrast=\"auto\">\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u3002\u5982\u679c<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> IEnumerable&lt;T&gt;<\/span> <\/span><span data-contrast=\"auto\">\u53c2\u6570\u5177\u6709<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> params<\/span> <\/span><span data-contrast=\"auto\">\u4fee\u9970\u7b26\uff0c\u8fd8\u53ef\u4ee5\u4f20\u9012\u9017\u53f7\u5206\u9694\u5217\u8868\u3002\u5f53\u6709\u5e38\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u5206\u9694\u5217\u8868\uff1b\u5f53\u60a8\u9700\u8981<\/span><span data-contrast=\"auto\">LINQ<\/span><span data-contrast=\"auto\">\u8868\u8fbe\u5f0f\u65f6\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public void WriteNames(params IEnumerable&lt;string&gt; names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));\r\n\r\nvar persons = new List&lt;Person&gt;\r\n{\r\n   new Person(\"Mads\", \"Torgersen\"),\r\n   new Person(\"Dustin\", \"Campbell\"),\r\n   new Person(\"Kathleen\", \"Dollard\")\r\n};\r\n\r\n\/\/ All of the following output: Mads, Dustin, Kathleen\r\nWriteNames(\"Mads\", \"Dustin\", \"Kathleen\");\r\nWriteNames(persons.Select(person =&gt; person.FirstName));\r\nWriteNames(from p in persons select p.FirstName);<\/code><\/pre>\n<h3><b><span data-contrast=\"auto\">\u91cd\u8f7d\u89e3\u6790<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u7f16\u5199\u65b9\u6cd5\u65f6\uff0c\u53ef\u4ee5\u63d0\u4f9b\u591a\u4e2a<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">params<\/span><span data-contrast=\"auto\">\u91cd\u8f7d\u3002\u4f8b\u5982\uff0c\u6dfb\u52a0<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> IEnumerable&lt;T&gt; <\/span><span data-contrast=\"auto\">\u91cd\u8f7d\u53ef\u652f\u6301<\/span><span data-contrast=\"auto\"> LINQ<\/span><span data-contrast=\"auto\">\uff0c\u6dfb\u52a0<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> ReadOnlySpan&lt;T&gt; <\/span><span data-contrast=\"auto\">\u6216<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> Span&lt;T&gt; <\/span><span data-contrast=\"auto\">\u91cd\u8f7d\u53ef\u51cf\u5c11\u5206\u914d\uff0c\u4ece\u800c\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public void WriteNames(params string[] names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));\r\n\r\npublic void WriteNames(params ReadOnlySpan&lt;string&gt; names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));\r\n\r\npublic void WriteNames(params IEnumerable&lt;string&gt; names)\r\n   =&gt; Console.WriteLine(String.Join(\", \", names));<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u5f53\u4f20\u9012\u6307\u5b9a\u7c7b\u578b\u4e4b\u4e00\u65f6\uff0c\u5c06\u4f7f\u7528\u8be5\u91cd\u8f7d\u3002\u5f53\u4f20\u9012\u9017\u53f7\u5206\u9694\u503c\u6216\u4e0d\u4f20\u9012\u4efb\u4f55\u503c\u65f6\uff0c\u5c06\u9009\u62e9\u6700\u4f73\u91cd\u8f7d\u3002\u4f7f\u7528\u4e0a\u8ff0\u91cd\u8f7d\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ IEnumerable overload is used\r\nWriteNames(persons.Select(person =&gt; person.FirstName)); \r\n\r\n\/\/ array overload is used\r\nWriteNames(new string[] {\"Mads\", \"Dustin\", \"Kathleen\"}); \r\n\r\n\/\/ most efficient overload is used: currently ReadOnlySpan\r\nWriteNames(\"Mads\", \"Dustin\", \"Kathleen\");                <\/code><\/pre>\n<p><span data-contrast=\"auto\">\u591a\u91cd\u91cd\u8f7d\u53ef\u4ee5\u589e\u52a0\u4fbf\u5229\u6027\u5e76\u63d0\u9ad8\u6027\u80fd\u3002\u5e93\u4f5c\u8005\u5e94\u8be5\u4e3a\u6240\u6709\u91cd\u8f7d\u63d0\u4f9b\u76f8\u540c\u7684\u8bed\u4e49\uff0c\u8fd9\u6837\u8c03\u7528\u8005\u5c31\u4e0d\u9700\u8981\u5173\u5fc3\u4f7f\u7528\u4e86\u54ea\u4e2a\u91cd\u8f7d<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><span style=\"color: #ff0000;\"><b>lock<\/b><\/span><b><span data-contrast=\"auto\">\u5bf9\u8c61<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">.NET 9 <\/span><span data-contrast=\"auto\">\u5305\u542b\u4e00\u79cd\u65b0\u7684\u7528\u4e8e\u4e92\u65a5\u7684<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> System.Threading.Lock<\/span> <\/span><span data-contrast=\"auto\">\u7c7b\u578b\uff0c\u6bd4\u4ec5\u5728\u4efb\u610f<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> System.Object<\/span> <\/span><span data-contrast=\"auto\">\u5b9e\u4f8b\u4e0a\u8fdb\u884c\u9501\u5b9a\u66f4\u6709\u6548\u3002<\/span><a href=\"https:\/\/github.com\/dotnet\/runtime\/issues\/34812\"><span data-contrast=\"auto\">System.Threading.Lock <\/span><span data-contrast=\"none\">\u7c7b\u578b\u63d0\u6848<\/span><\/a><span data-contrast=\"auto\">\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u8be5\u7c7b\u578b\u53ca\u5176\u521b\u5efa\u539f\u56e0\u3002\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u8be5\u7c7b\u578b\u6709\u671b\u6210\u4e3a<\/span><span data-contrast=\"auto\"> C# <\/span><span data-contrast=\"auto\">\u4ee3\u7801\u4e2d\u5927\u591a\u6570\u9501\u5b9a\u7684\u4e3b\u8981\u673a\u5236<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u4f7f\u8be5\u7c7b\u578b\u7684\u4f7f\u7528\u53d8\u5f97\u7b80\u5355\u3002\u5f53\u7f16\u8bd1\u5668\u8bc6\u522b\u51fa<\/span><span data-contrast=\"auto\"> lock <\/span><span data-contrast=\"auto\">\u8bed\u53e5\u7684\u76ee\u6807\u662f<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> System.Threading.Lock <\/span><span data-contrast=\"auto\">\u5bf9\u8c61\u65f6\uff0c<\/span><span data-contrast=\"auto\">C# <\/span><span data-contrast=\"auto\">\u5c31\u4f1a\u751f\u6210\u5bf9<\/span><span data-contrast=\"auto\"> System.Threading.Lock API <\/span><span data-contrast=\"auto\">\u7684\u8c03\u7528\uff0c\u5e76\u5728<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> Lock<\/span> <\/span><span data-contrast=\"auto\">\u5b9e\u4f8b\u53ef\u80fd\u88ab\u9519\u8bef\u5730\u89c6\u4e3a\u666e\u901a<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">object<\/span><span data-contrast=\"auto\">\u7684\u60c5\u51b5\u4e0b\u63d0\u4f9b\u8b66\u544a<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6b64\u66f4\u65b0\u610f\u5473\u7740<\/span><span data-contrast=\"auto\"> lock <\/span><span data-contrast=\"auto\">\u8bed\u53e5\u7684\u719f\u6089\u8bed\u6cd5\u5229\u7528\u4e86\u8fd0\u884c\u65f6\u4e2d\u7684\u65b0\u529f\u80fd\u3002\u719f\u6089\u7684\u4ee3\u7801\u53ea\u9700\u8fdb\u884c\u5c11\u91cf\u66f4\u6539\u5373\u53ef\u53d8\u5f97\u66f4\u597d\u3002\u53ea\u9700\u5c06\u9879\u76ee\u7684<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> TargetFramework <\/span><span data-contrast=\"auto\">\u66f4\u6539\u4e3a<\/span><span data-contrast=\"auto\"> .NET 9<\/span><span data-contrast=\"auto\">\uff0c\u5e76\u5c06<\/span><span data-contrast=\"auto\">lock<\/span><span data-contrast=\"auto\">\u7684\u7c7b\u578b\u4ece<\/span><span data-contrast=\"auto\">object<\/span><span data-contrast=\"auto\">\u66f4\u6539\u4e3a<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> System.Threading.Lock<\/span>\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">public class MyClass \r\n{\r\n    private object myLock = new object();\r\n\r\n    public void MyMethod() \r\n    {\r\n        lock (myLock)\r\n        {\r\n           \/\/ Your code\r\n        }          \r\n    }\r\n}\r\n\r\npublic class MyClass \r\n{\r\n    \/\/ The following line is the only change\r\n    private System.Threading.Lock myLock = new System.Threading.Lock();\r\n\r\n    public void MyMethod() \r\n    {\r\n        lock (myLock)\r\n        {\r\n            \/\/ Your code\r\n        }     \r\n    }\r\n}<\/code><\/pre>\n<h3><b><span data-contrast=\"auto\">\u4ece\u521d\u59cb\u5316\u5668\u672b\u5c3e\u5f00\u59cb\u7684\u7d22\u5f15<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u7d22\u5f15\u8fd0\u7b97\u7b26<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ^<\/span> <\/span><span data-contrast=\"auto\">\u5141\u8bb8\u60a8\u5728\u53ef\u8ba1\u6570\u96c6\u5408\u4e2d\u76f8\u5bf9\u4e8e\u96c6\u5408\u672b\u5c3e\u6307\u5b9a\u4e00\u4e2a\u4f4d\u7f6e\u3002\u8fd9\u73b0\u5728\u9002\u7528\u4e8e\u521d\u59cb\u5316\u5668<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">class Program\r\n{ \r\n    static void Main()\r\n    {\r\n        var x = new Numbers\r\n        {\r\n            Values = \r\n            {\r\n                [1] = 111,\r\n                [^1] = 999  \/\/ Works starting in C# 13\r\n            }\r\n            \/\/ x.Values[1] is 111\r\n            \/\/ x.Values[9] is 999, since it is the last element\r\n        };\r\n    }\r\n}\r\n\r\nclass Numbers\r\n{\r\n    public int[] Values { get; set; } = new int[10];\r\n} <\/code><\/pre>\n<h3><b><span data-contrast=\"auto\">\u8f6c\u4e49\u5e8f\u5217<\/span><\/b><span style=\"color: #ff0000;\"><b> \\e<\/b>\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u4e3a\u4f17\u6240\u719f\u77e5\u7684<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ESCAPE<\/span> <\/span><span data-contrast=\"auto\">\u6216<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ESC<\/span> <\/span><span data-contrast=\"auto\">\u5b57\u7b26\u5f15\u5165\u4e86\u65b0\u7684\u8f6c\u4e49\u5e8f\u5217\u3002\u4ee5\u524d\u60a8\u5fc5\u987b\u5c06\u5176\u8f93\u5165\u4e3a<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> \\u001b<\/span> <\/span><span data-contrast=\"auto\">\u7684\u53d8\u4f53\u3002\u5f53\u4f7f\u7528<\/span><span data-contrast=\"auto\"> VT100\/ANSI <\/span><span data-contrast=\"auto\">\u8f6c\u4e49\u7801\u4e0e<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> System.Console <\/span><span data-contrast=\"auto\">\u7684\u7ec8\u7aef\u4ea4\u4e92\u65f6\uff0c\u6b64\u65b0\u5e8f\u5217\u7279\u522b\u65b9\u4fbf\u3002\u4f8b\u5982<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\/\/ Prior to C# 13\r\nConsole.WriteLine(\"\\u001b[1mThis is a bold text\\u001b[0m\");\r\n\r\n\/\/ With C# 13\r\nConsole.WriteLine(\"\\e[1mThis is a bold text\\e[0m\");<\/code><\/pre>\n<p><span data-contrast=\"none\">Console.WriteLine(<\/span><span data-contrast=\"none\">&#8220;\\e[1mThis is a bold text\\e[0m&#8221;<\/span><span data-contrast=\"none\">);<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u8fd9\u4f7f\u5f97\u521b\u5efa\u7cbe\u7f8e\u7684\u7ec8\u7aef\u8f93\u51fa\u53d8\u5f97\u66f4\u5bb9\u6613\u5e76\u4e14\u66f4\u4e0d\u5bb9\u6613\u51fa\u9519<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">Partial<\/span><\/b><b><span data-contrast=\"auto\">\u5c5e\u6027<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u6dfb\u52a0\u4e86<\/span><span data-contrast=\"auto\">partial<\/span><span data-contrast=\"auto\">\u5c5e\u6027\u3002\u4e0e<\/span><span data-contrast=\"auto\">partial<\/span><span data-contrast=\"auto\">\u65b9\u6cd5\u4e00\u6837\uff0c\u5b83\u4eec\u7684\u4e3b\u8981\u76ee\u7684\u662f\u652f\u6301\u6e90\u751f\u6210\u5668\u3002<\/span><span data-contrast=\"auto\">partial<\/span><span data-contrast=\"auto\">\u65b9\u6cd5\u5df2\u5728\u8bb8\u591a\u7248\u672c\u4e2d\u53ef\u7528\uff0c\u5e76\u5728<\/span><span data-contrast=\"auto\"> C# 9 <\/span><span data-contrast=\"auto\">\u4e2d\u8fdb\u884c\u4e86\u989d\u5916\u7684\u6539\u8fdb\u3002<\/span><span data-contrast=\"auto\">partial<\/span><span data-contrast=\"auto\">\u5c5e\u6027\u4e0e\u5b83\u4eec\u7684<\/span><span data-contrast=\"auto\">partial<\/span><span data-contrast=\"auto\">\u65b9\u6cd5\u975e\u5e38\u76f8\u4f3c<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u4f8b\u5982\uff0c\u4ece<\/span><span data-contrast=\"auto\"> .NET 7\uff08C# 12<\/span><span data-contrast=\"auto\">\uff09\u5f00\u59cb\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u6e90\u751f\u6210\u5668\u4e3a\u65b9\u6cd5\u521b\u5efa\u9ad8\u6548\u7684\u4ee3\u7801<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[GeneratedRegex(\"abc|def\")]\r\nprivate static partial Regex AbcOrDefMethod();\r\n\r\nif (AbcOrDefMethod().IsMatch(text))\r\n{\r\n   \/\/ Take action with matching text\r\n}<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u5728<\/span><span data-contrast=\"auto\"> .NET 9\uff08C# 13<\/span><span data-contrast=\"auto\">\uff09\u4e2d\uff0c<\/span><span data-contrast=\"auto\">Regex <\/span><span data-contrast=\"auto\">\u6e90\u751f\u6210\u5668\u5df2\u66f4\u65b0\uff0c\u5982\u679c\u60a8\u66f4\u559c\u6b22\u4f7f\u7528\u5c5e\u6027\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[GeneratedRegex(\"abc|def\")]\r\nprivate static partial Regex AbcOrDefProperty { get; };\r\n\r\nif (AbcOrDefProperty.IsMatch(text))\r\n{\r\n   \/\/ Take action with matching text\r\n}<\/code><\/pre>\n<p><span data-contrast=\"auto\">Partial<\/span><span data-contrast=\"auto\">\u5c5e\u6027\u5c06\u4f7f\u6e90\u751f\u6210\u5668\u8bbe\u8ba1\u4eba\u5458\u66f4\u5bb9\u6613\u521b\u5efa\u81ea\u7136\u611f\u89c9\u7684<\/span><span data-contrast=\"auto\"> API\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">\u65b9\u6cd5\u7ec4\u81ea\u7136\u7c7b\u578b\u6539\u8fdb<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u8868\u8fbe\u5f0f\u7684\u81ea\u7136\u7c7b\u578b\u662f\u7531\u7f16\u8bd1\u5668\u786e\u5b9a\u7684\u7c7b\u578b\uff0c\u4f8b\u5982\u5f53\u7c7b\u578b\u5206\u914d\u7ed9<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> var<\/span> <\/span><span data-contrast=\"auto\">\u6216<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> Delegate<\/span> <\/span><span data-contrast=\"auto\">\u65f6\u3002\u5f53\u5b83\u662f\u4e00\u4e2a\u7b80\u5355\u7c7b\u578b\u65f6\uff0c\u8fd9\u5f88\u7b80\u5355\u3002\u5728<\/span><span data-contrast=\"auto\"> C# 10 <\/span><span data-contrast=\"auto\">\u4e2d\uff0c\u6211\u4eec\u6dfb\u52a0\u4e86\u5bf9\u65b9\u6cd5\u7ec4\u7684\u652f\u6301\u3002\u5f53\u60a8\u5c06\u4e0d\u5e26\u62ec\u53f7\u7684\u65b9\u6cd5\u540d\u79f0\u4f5c\u4e3a\u59d4\u6258\u5305\u542b\u65f6\uff0c\u5c06\u4f7f\u7528\u65b9\u6cd5\u7ec4<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">Todo GetTodo() =&gt; new(Id: 0, Name: \"Name\");\r\nvar f = GetTodo; \/\/ the type of f is Func&lt;ToDo&gt;<\/code><\/pre>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5b8c\u5584\u4e86\u786e\u5b9a\u81ea\u7136\u7c7b\u578b\u7684\u89c4\u5219\uff0c\u4ee5\u4fbf\u6839\u636e\u8303\u56f4\u8003\u8651\u5019\u9009\u8005\u5e76\u5220\u9664\u6ca1\u6709\u6210\u529f\u673a\u4f1a\u7684\u5019\u9009\u8005\u3002\u66f4\u65b0\u8fd9\u4e9b\u89c4\u5219\u610f\u5473\u7740\u5728\u4f7f\u7528\u65b9\u6cd5\u7ec4\u65f6\u7f16\u8bd1\u5668\u9519\u8bef\u4f1a\u66f4\u5c11<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><span style=\"color: #ff0000;\"><b>allows ref struct<\/b>\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u6dfb\u52a0\u4e86\u4e00\u79cd\u6307\u5b9a\u6cdb\u578b\u7c7b\u578b\u53c2\u6570\u529f\u80fd\u7684\u65b0\u65b9\u6cd5\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7c7b\u578b\u53c2\u6570\u4e0d\u80fd\u4e3a<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">ref struct<\/span>\u3002<\/span><span data-contrast=\"auto\">\u4f46\u662f<\/span><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5141\u8bb8\u60a8\u6307\u5b9a\u7c7b\u578b\u53c2\u6570\u53ef\u4ee5\u662f<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> ref struct<\/span><span data-contrast=\"auto\">\uff0c\u5e76\u5e94\u7528\u76f8\u5e94\u7684\u89c4\u5219\u3002\u867d\u7136\u5176\u4ed6\u6cdb\u578b\u7ea6\u675f\u9650\u5236\u4e86\u53ef\u7528\u4f5c\u7c7b\u578b\u53c2\u6570\u7684\u7c7b\u578b\u96c6\uff0c\u4f46\u6b64\u65b0\u89c4\u8303\u6269\u5c55\u4e86\u5141\u8bb8\u7684\u7c7b\u578b\u3002\u6211\u4eec\u8ba4\u4e3a\u8fd9\u662f\u4e00\u79cd\u53cd\u7ea6\u675f\uff0c\u56e0\u4e3a\u5b83\u5220\u9664\u4e86\u9650\u5236\uff0c\u800c\u4e0d\u662f\u6dfb\u52a0\u4e86\u9650\u5236\u3002<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">where <\/span><span data-contrast=\"auto\">\u5b50\u53e5\u4e2d\u7684\u8bed\u6cd5<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">allows ref struct<\/span><span data-contrast=\"auto\">\uff0c\u5176\u4e2d<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">allows<\/span><span data-contrast=\"auto\">\u8868\u793a\u7528\u6cd5\u4e0a\u7684\u6269\u5c55<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">T Identity&lt;T&gt;(T p)\r\n    where T : allows ref struct\r\n    =&gt; p;\r\n\r\n\/\/ Okay\r\nSpan&lt;int&gt; local = Identity(new Span&lt;int&gt;(new int[10]));<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u4f7f\u7528<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\">allows ref struct<\/span> <\/span><span data-contrast=\"auto\">\u6307\u5b9a\u7684\u7c7b\u578b\u53c2\u6570\u5177\u6709<\/span> <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/language-reference\/builtin-types\/ref-struct\"><span data-contrast=\"auto\">ref struct <\/span><span data-contrast=\"none\">\u7c7b\u578b\u7684\u6240\u6709\u884c\u4e3a\u548c\u9650\u5236<\/span><\/a><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><span style=\"color: #ff0000;\"><b>async<\/b><\/span><b><span data-contrast=\"auto\">\u65b9\u6cd5\u548c\u8fed\u4ee3\u5668\u4e2d\u7684<\/span><\/b><b><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ref<\/span> <\/span><\/b><b><span data-contrast=\"auto\">\u548c<\/span><\/b><span style=\"color: #ff0000;\"><b> unsafe<\/b>\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u5728<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u4e4b\u524d\uff0c\u8fed\u4ee3\u5668\u65b9\u6cd5\uff08\u4f7f\u7528<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> yield return <\/span><span data-contrast=\"auto\">\u7684\u65b9\u6cd5\uff09\u548c<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">async<\/span><span data-contrast=\"auto\">\u65b9\u6cd5\u4e0d\u80fd\u58f0\u660e\u5c40\u90e8<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">ref<\/span><span data-contrast=\"auto\">\u53d8\u91cf\uff0c\u4e5f\u4e0d\u80fd\u5177\u6709<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">unsafe<\/span><span data-contrast=\"auto\">\u7684\u4e0a\u4e0b\u6587<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5728<\/span><span data-contrast=\"auto\"> C# 13 <\/span><span data-contrast=\"auto\">\u4e2d\uff0c<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">async<\/span><span data-contrast=\"auto\">\u65b9\u6cd5\u53ef\u4ee5\u58f0\u660e<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> ref <\/span><span data-contrast=\"auto\">\u5c40\u90e8\u53d8\u91cf\uff0c\u6216<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ref struct<\/span> <\/span><span data-contrast=\"auto\">\u7c7b\u578b\u7684\u5c40\u90e8\u53d8\u91cf\u3002\u8fd9\u4e9b\u53d8\u91cf\u4e0d\u80fd\u8de8<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> await<\/span> <\/span><span data-contrast=\"auto\">\u8fb9\u754c\u6216<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> yield return <\/span><span data-contrast=\"auto\">\u8fb9\u754c\u4fdd\u5b58<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u540c\u6837\uff0c<\/span><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5141\u8bb8\u8fed\u4ee3\u5668\u65b9\u6cd5\u4e2d\u4f7f\u7528<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">unsafe<\/span><span data-contrast=\"auto\">\u4e0a\u4e0b\u6587\u3002\u4f46\u662f\uff0c\u6240\u6709<\/span><span data-contrast=\"auto\"> <span style=\"color: #ff0000;\" data-contrast=\"auto\">yield return <\/span><\/span><span data-contrast=\"auto\">\u548c<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> await<\/span> <\/span><span data-contrast=\"auto\">\u8bed\u53e5\u90fd\u5fc5\u987b\u5728<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\">safe<\/span><span data-contrast=\"auto\">\u4e0a\u4e0b\u6587\u4e2d\u3002\u8fd9\u4e9b\u653e\u5bbd\u7684\u9650\u5236\u8ba9\u60a8\u53ef\u4ee5\u5728\u66f4\u591a\u5730\u65b9\u4f7f\u7528<\/span><span data-contrast=\"auto\"><span style=\"color: #ff0000;\"> ref<\/span> <\/span><span data-contrast=\"auto\">\u5c40\u90e8\u53d8\u91cf\u548c<\/span><span style=\"color: #ff0000;\" data-contrast=\"auto\"> ref struct<\/span><span data-contrast=\"auto\">\u7c7b\u578b\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">\u6269\u5c55\u7c7b\u578b\u7684\u66f4\u65b0<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u6211\u4eec\u5bf9<\/span> <a href=\"https:\/\/aka.ms\/build2024-csharp\"><span data-contrast=\"auto\">Mads <\/span><span data-contrast=\"auto\">\u548c<\/span><span data-contrast=\"auto\"> Dustin <\/span><span data-contrast=\"auto\">\u5728<\/span><span data-contrast=\"auto\"> Build <\/span><span data-contrast=\"none\">\u4e0a\u5c55\u793a\u7684<\/span><\/a><span data-contrast=\"auto\">\u6269\u5c55\u7c7b\u578b\u529f\u80fd\u611f\u5230\u975e\u5e38\u5174\u594b\u3002\u6211\u4eec\u8fd8\u5728<\/span><span data-contrast=\"auto\">Build<\/span><span data-contrast=\"auto\">\u4e0a\u7684\u535a\u5ba2\u6587\u7ae0<\/span> <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/dotnet-build-2024-announcements\/\"><span data-contrast=\"auto\">.NET <\/span><span data-contrast=\"none\">\u516c\u544a<\/span><\/a><span data-contrast=\"auto\">\u4e2d\u4ecb\u7ecd\u4e86\u6269\u5c55\u7c7b\u578b\u3002\u5f53\u65f6\uff0c\u6211\u4eec\u7684\u76ee\u6807\u662f\u5728<\/span><span data-contrast=\"auto\">C# 13<\/span><span data-contrast=\"auto\">\u4e2d\u5b9e\u73b0\u8be5\u529f\u80fd\u7684\u5173\u952e\u90e8\u5206\uff0c\u4f46\u8bbe\u8ba1\u548c\u5b9e\u73b0\u5c06\u9700\u8981\u66f4\u591a\u7684\u65f6\u95f4\u3002\u8bf7\u5728\u65e9\u671f\u7684<\/span><span data-contrast=\"auto\"> C# 14\uff08NET 10<\/span><span data-contrast=\"auto\">\uff09\u9884\u89c8\u7248\u4e2d\u67e5\u627e\u6269\u5c55\u7c7b\u578b<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<h3><b><span data-contrast=\"auto\">\u603b\u7ed3<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">\u60a8\u53ef\u4ee5\u5728<\/span> <a href=\"https:\/\/learn.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-13\"><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"none\">\u7684\u65b0\u589e\u529f\u80fd<\/span><\/a><span data-contrast=\"auto\">\u4e2d\u4e86\u89e3\u66f4\u591a\u76f8\u5173\u5185\u5bb9\u3002\u6211\u4eec\u4ecd\u5728\u4e3a<\/span><span data-contrast=\"auto\">C# 13 <\/span><span data-contrast=\"auto\">\u5f00\u53d1\u65b0\u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u5728<\/span> <a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/main\/docs\/Language%20Feature%20Status.md\"><span data-contrast=\"auto\">Roslyn <\/span><span data-contrast=\"none\">\u529f\u80fd\u72b6\u6001\u9875\u9762<\/span><\/a><span data-contrast=\"auto\">\u67e5\u770b\u6211\u4eec\u6b63\u5728\u505a\u7684\u4e8b\u60c5\u3002\u6b64\u5916\uff0c\u8bf7\u52a1\u5fc5\u5173\u6ce8<\/span> <a href=\"https:\/\/github.com\/dotnet\/core\/tree\/main\/release-notes\/9.0\"><span data-contrast=\"auto\">.NET 9 <\/span><span data-contrast=\"none\">\u9884\u89c8\u7248\u53d1\u884c\u8bf4\u660e<\/span><\/a><span data-contrast=\"auto\">\uff0c\u60a8\u73b0\u5728\u53ef\u4ee5\u5728\u5176\u4e2d\u627e\u5230\u6bcf\u4e2a\u7248\u672c\u7684<\/span><span data-contrast=\"auto\"> C# <\/span><span data-contrast=\"auto\">\u53d1\u884c\u8bf4\u660e\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u8bf7\u4e0b<\/span><span data-contrast=\"auto\">\u200b\u200b<\/span><span data-contrast=\"auto\">\u8f7d\u5e26\u6709<\/span><span data-contrast=\"auto\"> .NET 9 <\/span><span data-contrast=\"auto\">\u7684<\/span> <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\"><span data-contrast=\"none\">Visual Studio 2022-17.11<\/span><\/a> <span data-contrast=\"auto\">\u7684\u6700\u65b0\u9884\u89c8\u7248\uff0c\u4f53\u9a8c\u8fd9\u4e9b\u65b0\u529f\u80fd\uff0c\u5e76\u544a\u8bc9\u6211\u4eec\u60a8\u7684\u60f3\u6cd5<\/span><span data-contrast=\"auto\">\uff01<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u6280\u672f\u95ee\u9898\uff0c\u6b22\u8fce\u6765<a href=\"https:\/\/learn.microsoft.com\/zh-cn\/answers\/tags\/309\/csharp\" target=\"_blank\" rel=\"noopener\">Microsoft Q&amp;A<\/a>\u00a0\u63d0\u95ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eKathleen Dollard\u00a0\u7684C# 13: Explore the latest preview features &#8211; .NET Blog (microsoft.com)\u00a0 C# 13 \u5df2\u521d\u5177\u96cf\u5f62\uff0c\u5176\u65b0\u7279\u6027\u4fa7\u91cd\u4e8e\u7075\u6d3b\u6027\u3001\u6027\u80fd\u4ee5\u53ca\u4f7f\u60a8\u6700\u559c\u6b22\u7684\u529f\u80fd\u5728\u65e5\u5e38\u4e2d\u53d8\u5f97\u66f4\u5bb9\u6613\u4f7f\u7528\u3002\u6211\u4eec\u4ee5\u516c\u5f00\u7684\u65b9\u5f0f\u6784\u5efa C#\uff0c\u5728\u4eca\u5e74\u7684 Microsoft Build \u5927\u4f1a\u4e0a\uff0c\u6211\u4eec\u4f1a\u8ba9\u60a8\u4e00\u7779 C# 13 \u7684\u7cbe\u5f69\u4e4b\u5904\u3002\u4eca\u5929\uff0c\u6211\u4eec\u60f3\u5206\u4eab\u4e00\u4e0bC# 13 \u5f53\u524d\u7684\u72b6\u6001\uff0c\u4ee5\u53ca\u60a8\u4eca\u5929\u5c31\u53ef\u4ee5\u5c1d\u8bd5\u7684\u65b0\u529f\u80fd\uff0c\u5e76\u63d0\u4f9b\u6709\u5173\u6b64\u7248\u672c\u53ca\u4ee5\u540e\u8ba1\u5212\u4e2d\u7684\u529f\u80fd\u66f4\u65b0\u3002\u8ba9\u6211\u4eec\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3\u8fd9\u4e9b\u65b0\u529f\u80fd\u3002\u00a0 \u589e\u5f3a\u4e86 params \u96c6\u5408\u4ee5\u5b9e\u73b0\u66f4\u5f3a\u7684\u7075\u6d3b\u6027 lock\u5bf9\u8c61 \u7d22\u5f15\u8fd0\u7b97\u7b26\u6539\u8fdb \u8f6c\u4e49\u5e8f\u5217 \\e Partial\u5c5e\u6027 \u65b9\u6cd5\u7ec4\u81ea\u7136\u7c7b\u578b\u6539\u8fdb async\u65b9\u6cd5\u548c\u8fed\u4ee3\u5668\u4e2d\u7684 ref \u548c unsafe \u6269\u5c55\u7c7b\u578b\u66f4\u65b0 \u7acb\u5373\u8bd5\u7528 C# 13\u00a0 \u5728\u6211\u4eec\u6df1\u5165\u7814\u7a76 C# 13 \u7684\u6bcf\u4e2a\u65b0\u529f\u80fd\u4e4b\u524d\uff0c\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\u5982\u4f55\u4f7f\u7528\u5b83\u3002\u00a0 \u60a8\u53ef\u4ee5\u5728\u6700\u65b0\u7684 .NET 9 \u9884\u89c8\u7248\uff08\u64b0\u5199\u672c\u6587\u65f6\u4e3a\u9884\u89c8\u7248 6\uff09\u548c Visual Studio 2022-17.11 \u7684\u6700\u65b0\u9884\u89c8\u7248\u4e2d\u627e\u5230 C# [&hellip;]<\/p>\n","protected":false},"author":97248,"featured_media":774,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[52,53,54,15],"class_list":["post-772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-ch","tag-net-9","tag-c-13","tag-csharp","tag-featured-preview"],"acf":[],"blog_post_summary":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eKathleen Dollard\u00a0\u7684C# 13: Explore the latest preview features &#8211; .NET Blog (microsoft.com)\u00a0 C# 13 \u5df2\u521d\u5177\u96cf\u5f62\uff0c\u5176\u65b0\u7279\u6027\u4fa7\u91cd\u4e8e\u7075\u6d3b\u6027\u3001\u6027\u80fd\u4ee5\u53ca\u4f7f\u60a8\u6700\u559c\u6b22\u7684\u529f\u80fd\u5728\u65e5\u5e38\u4e2d\u53d8\u5f97\u66f4\u5bb9\u6613\u4f7f\u7528\u3002\u6211\u4eec\u4ee5\u516c\u5f00\u7684\u65b9\u5f0f\u6784\u5efa C#\uff0c\u5728\u4eca\u5e74\u7684 Microsoft Build \u5927\u4f1a\u4e0a\uff0c\u6211\u4eec\u4f1a\u8ba9\u60a8\u4e00\u7779 C# 13 \u7684\u7cbe\u5f69\u4e4b\u5904\u3002\u4eca\u5929\uff0c\u6211\u4eec\u60f3\u5206\u4eab\u4e00\u4e0bC# 13 \u5f53\u524d\u7684\u72b6\u6001\uff0c\u4ee5\u53ca\u60a8\u4eca\u5929\u5c31\u53ef\u4ee5\u5c1d\u8bd5\u7684\u65b0\u529f\u80fd\uff0c\u5e76\u63d0\u4f9b\u6709\u5173\u6b64\u7248\u672c\u53ca\u4ee5\u540e\u8ba1\u5212\u4e2d\u7684\u529f\u80fd\u66f4\u65b0\u3002\u8ba9\u6211\u4eec\u66f4\u8be6\u7ec6\u5730\u4e86\u89e3\u8fd9\u4e9b\u65b0\u529f\u80fd\u3002\u00a0 \u589e\u5f3a\u4e86 params \u96c6\u5408\u4ee5\u5b9e\u73b0\u66f4\u5f3a\u7684\u7075\u6d3b\u6027 lock\u5bf9\u8c61 \u7d22\u5f15\u8fd0\u7b97\u7b26\u6539\u8fdb \u8f6c\u4e49\u5e8f\u5217 \\e Partial\u5c5e\u6027 \u65b9\u6cd5\u7ec4\u81ea\u7136\u7c7b\u578b\u6539\u8fdb async\u65b9\u6cd5\u548c\u8fed\u4ee3\u5668\u4e2d\u7684 ref \u548c unsafe \u6269\u5c55\u7c7b\u578b\u66f4\u65b0 \u7acb\u5373\u8bd5\u7528 C# 13\u00a0 \u5728\u6211\u4eec\u6df1\u5165\u7814\u7a76 C# 13 \u7684\u6bcf\u4e2a\u65b0\u529f\u80fd\u4e4b\u524d\uff0c\u60a8\u53ef\u80fd\u60f3\u77e5\u9053\u5982\u4f55\u4f7f\u7528\u5b83\u3002\u00a0 \u60a8\u53ef\u4ee5\u5728\u6700\u65b0\u7684 .NET 9 \u9884\u89c8\u7248\uff08\u64b0\u5199\u672c\u6587\u65f6\u4e3a\u9884\u89c8\u7248 6\uff09\u548c Visual Studio 2022-17.11 \u7684\u6700\u65b0\u9884\u89c8\u7248\u4e2d\u627e\u5230 C# [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/97248"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=772"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/774"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}