{"id":1503,"date":"2025-03-10T00:40:19","date_gmt":"2025-03-09T16:40:19","guid":{"rendered":"http:\/\/codermr.com\/?p=1503"},"modified":"2025-03-10T00:40:19","modified_gmt":"2025-03-09T16:40:19","slug":"c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/","title":{"rendered":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">C# Generics<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the C# generics \u3010\u6cdb\u578b\u65b9\u6cd5\u3011<\/h2>\n\n\n\n<p>C# generics allow you to write code that <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">works with more than one type<\/mark><\/strong>. By using generics, <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">you can write code with placeholders for types<\/mark><\/strong> and then provide the actual types when using the code.<\/p>\n\n\n\n<p>Generics introduces the concept of <strong><em>type parameters<\/em><\/strong> to .NET.  Generics make it possible to design <strong><em>classes and methods<\/em><\/strong> that(\u6307&#8221;<strong><em>classes and methods<\/em><\/strong>&#8220;) <strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">defer the specification of one or more type parameters<\/mark><\/strong> until you use the class or method in your code. \u3010\u6cdb\u578b\u5f15\u5165\u4e86\u7c7b\u578b\u53c2\u6570\u7684\u6982\u5ff5\u3002\u6cdb\u578b\u4f7f\u8bbe\u8ba1\u7c7b\u548c\u65b9\u6cd5\u6210\u4e3a\u53ef\u80fd\uff0c\u8fd9\u4e9b\u7c7b\u548c\u65b9\u6cd5\u53ef\u4ee5\u63a8\u8fdf\u4e00\u4e2a\u6216\u591a\u4e2a\u7c7b\u578b\u53c2\u6570\u7684\u89c4\u8303\uff0c\u76f4\u5230\u60a8\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\u8be5\u7c7b\u6216\u65b9\u6cd5\u3002\u3011<\/p>\n\n\n\n<p>Suppose you need to write a method that swaps the values of two&nbsp;<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-integer\/\">integer<\/a>&nbsp;variables. To do that, you can define a method called&nbsp;<code>SwapInt()<\/code>&nbsp;that accepts two integer parameters like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static void SwapInt(ref int a, ref int b)\n{\n    int temp = a;\n        a = b;\n        b = temp;\n}<\/code><\/pre>\n\n\n\n<p>Later, you want to swap the values of two\u00a0<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-string\/\">string<\/a>\u00a0variables. In this case, you need to define a new method that swaps the strings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static void SwapString(ref string a, ref string b)\n{\n    string temp = a;\n           a = b;\n           b = temp;\n}<\/code><\/pre>\n\n\n\n<p>Both&nbsp;<code>SwapInt()<\/code>&nbsp;and&nbsp;<code>SwapString()<\/code>&nbsp;methods have the same logic except for the types of the variables that they deal with.<\/p>\n\n\n\n<p>Imagine that you need to swap values of two variables of a new type e.g.,&nbsp;<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-float\/\">float<\/a>, you need to define a new method for each new type. As the result, you\u2019ll have lots of&nbsp;<code>Swap*<\/code>&nbsp;methods with the same logic.<\/p>\n\n\n\n<p>To resolve this, you can create a generic method that swaps values of variables of any type like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static void Swap&lt;T>(ref T a, ref T b)\n{\n    T temp = a;\n      a = b;\n      b = temp;\n}<\/code><\/pre>\n\n\n\n<p>In this\u00a0<code>Swap()<\/code>\u00a0method, instead of using a specific type, we use the placeholder T for the type.<\/p>\n\n\n\n<p>When using the\u00a0<code>Swap()<\/code>\u00a0method, you can specify the specific type. For example:<\/p>\n\n\n\n<p>int x = 10, y = 20; Swap&lt;int>(ref x, ref y);<\/p>\n\n\n\n<p>In this example, we specify the\u00a0<code>int<\/code>\u00a0type inside the angle brackets (<code>&lt;><\/code>) that follows the method name. Since the types of\u00a0<code>x<\/code>\u00a0and\u00a0<code>y<\/code>\u00a0are\u00a0<code>int<\/code>, you can make the method call short like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int x = 10, y = 20;\n\nSwap(ref x, ref y);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul>\n<li>C# generics allow you to write general-purpose code that uses the same type in multiple places without knowing that type upfront.<\/li>\n\n\n\n<li>Use C# generics to write reusable, type-neutral code.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u66f4\u591a\u6cdb\u578b\u7684\u4f7f\u7528<\/h2>\n\n\n\n<p>C# allows you to use generics with the following:<\/p>\n\n\n\n<ul>\n<li><a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-class\/\">Classes<\/a><\/li>\n\n\n\n<li>Methods<\/li>\n\n\n\n<li><a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-interface\/\">Interfaces<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/c-delegate\/\">Delegates<\/a><\/li>\n\n\n\n<li>Structs<\/li>\n<\/ul>\n\n\n\n<p>In practice, you\u2019ll find that generics are extensively used in the collection types like\u00a0<code>List&lt;T><\/code>,\u00a0<code>Stack&lt;T><\/code>,\u00a0<code>Queue&lt;T><\/code>, etc. These are called\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/api\/system.collections.generic\" target=\"_blank\" rel=\"noreferrer noopener\">generic collection types<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6cdb\u578b\u7c7b<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Introduction to the objects and classes<\/h2>\n\n\n\n<p>Objects are one of the essential concepts in object-oriented programming. Objects have states and behaviors:<\/p>\n\n\n\n<ul>\n<li>States represent the data that the object holds at a particular point in time.<strong>\uff08\u72b6\u6001\u8868\u793a\u5bf9\u8c61\u5728\u7279\u5b9a\u65f6\u95f4\u70b9\u4fdd\u5b58\u7684\u6570\u636e\u3002\uff09<\/strong><\/li>\n\n\n\n<li>Behaviors represent the actions that the object can perform to <strong>manipulate<\/strong> its states.<strong>\uff08\u884c\u4e3a\u8868\u793a\u5bf9\u8c61\u53ef\u4ee5\u6267\u884c\u6765\u64cd\u7eb5\u5176\u72b6\u6001\u7684\u52a8\u4f5c\u3002\uff09<\/strong><\/li>\n<\/ul>\n\n\n\n<p>C# uses class-based object-oriented programming. Before creating objects, you need to define a class. A class is a blueprint for creating objects.<\/p>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u2588\u2588 C# \u4e2d&#8221;\u6cdb\u578b\u7c7b&#8221;\u7684\u8bed\u6cd5\u548c Java \u4e2d\u4e00\u6837\uff1a<\/mark><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class MyGenericArray&lt;T>\n    {\n        private T&#91;] array;\n        public MyGenericArray(int size)\n        {\n            array = new T&#91;size + 1];\n        }\n        public T getItem(int index)\n        {\n            return array&#91;index];\n        }\n        public void setItem(int index, T value)\n        {\n            array&#91;index] = value;\n        }\n    }\n<strong>\/\/ \u521b\u5efa\u6cdb\u578b\u7c7b\uff08\u58f0\u660e\u4e00\u4e2a\u6574\u578b\u6570\u7ec4\uff09<\/strong>\nMyGenericArray&lt;int> intArray = new MyGenericArray&lt;int>(5);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6cdb\u578b\uff08Generic\uff09\u65b9\u6cd5<\/h2>\n\n\n\n<p>C# \u4e2d\u6cdb\u578b\u65b9\u6cd5\u7684\u58f0\u660e\u548c Java \u4e2d\u7684\u8bed\u6cd5\u4e0d\u592a\u4e00\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Program\n    {\n        static void Swap&lt;T>(ref T lhs, ref T rhs)\n        {\n            T temp;\n            temp = lhs;\n            lhs = rhs;\n            rhs = temp;\n        }\n        static void Main(string&#91;] args)\n        {\n            int a, b;\n            char c, d;\n            a = 10;\n            b = 20;\n            c = 'I';\n            d = 'V';\n\n            \/\/ \u5728\u4ea4\u6362\u4e4b\u524d\u663e\u793a\u503c\n            Console.WriteLine(\"Int values before calling swap:\");\n            Console.WriteLine(\"a = {0}, b = {1}\", a, b);\n            Console.WriteLine(\"Char values before calling swap:\");\n            Console.WriteLine(\"c = {0}, d = {1}\", c, d);\n\n            \/\/ \u8c03\u7528 swap\n            Swap&lt;int>(ref a, ref b);\n            Swap&lt;char>(ref c, ref d);\n\n            \/\/ \u5728\u4ea4\u6362\u4e4b\u540e\u663e\u793a\u503c\n            Console.WriteLine(\"Int values after calling swap:\");\n            Console.WriteLine(\"a = {0}, b = {1}\", a, b);\n            Console.WriteLine(\"Char values after calling swap:\");\n            Console.WriteLine(\"c = {0}, d = {1}\", c, d);\n            Console.ReadKey();\n        }\n    }<\/code><\/pre>\n\n\n\n<p>C# \u4e2d\u7684\u65b9\u6cd5\u58f0\u660e\u6cdb\u578b\uff0c\u548c Java \u4e2d\u7684\u65b9\u6cd5\u58f0\u660e\u6cdb\u578b\u65f6\uff0c\u8bed\u6cd5\u533a\u522b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-17.png\"><img loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"266\" src=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-17.png\" alt=\"\" class=\"wp-image-1509\" srcset=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-17.png 558w, http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/image-17-300x143.png 300w\" sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/a><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">C# Anonymous Methods  \u533f\u540d\u65b9\u6cd5<\/h1>\n\n\n\n<p><strong>\u533f\u540d\u65b9\u6cd5\uff08Anonymous methods\uff09<\/strong>&nbsp;\u63d0\u4f9b\u4e86\u4e00\u79cd\u4f20\u9012\u4ee3\u7801\u5757\u4f5c\u4e3a\u59d4\u6258\u53c2\u6570\u7684\u6280\u672f\u3002<\/p>\n\n\n\n<p>\u5728\u533f\u540d\u65b9\u6cd5\u4e2d\u60a8\u4e0d\u9700\u8981\u6307\u5b9a\u8fd4\u56de\u7c7b\u578b\uff0c\u5b83\u662f\u4ece\u65b9\u6cd5\u4e3b\u4f53\u5185\u7684 return \u8bed\u53e5\u63a8\u65ad\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lambda \u8868\u8fbe\u5f0f<\/h2>\n\n\n\n<p><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">Lambda \u8868\u8fbe\u5f0f\u662f\u4e00\u4e2a\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u7528\u4e8e\u521b\u5efa\u533f\u540d\u51fd\u6570\u3002\u5b83\u4eec\u901a\u5e38\u7528\u4e8e LINQ \u67e5\u8be2\u548c\u59d4\u6258\u3002<\/mark><\/strong><\/p>\n\n\n\n<p>\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(parameters) => expression\n\/\/ \u6216\n(parameters) => { statement; }<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u793a\u4f8b\uff1a\u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u5b9a\u4e49\u4e00\u4e2a\u59d4\u6258\nFunc&lt;int, int, int> add = (a, b) => a + b;\nConsole.WriteLine(add(2, 3)); \/\/ \u8f93\u51fa 5\n\n\/\/ \u793a\u4f8b\uff1a\u4f7f\u7528 Lambda \u8868\u8fbe\u5f0f\u8fc7\u6ee4\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\nint&#91;] numbers = { 1, 2, 3, 4, 5 };\nvar evenNumbers = numbers.Where(n => n % 2 == 0);\nforeach (var num in evenNumbers)\n{\n    Console.WriteLine(num); \/\/ \u8f93\u51fa 2 4\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u533f\u540d\u65b9\u6cd5<\/h2>\n\n\n\n<p>\u533f\u540d\u65b9\u6cd5\u662f\u901a\u8fc7\u4f7f\u7528\u00a0<strong>delegate<\/strong>\u00a0\u5173\u952e\u5b57\u521b\u5efa\u59d4\u6258\u5b9e\u4f8b\u6765\u58f0\u660e\u7684<strong>\u3010\u8fd9\u53e5\u8bdd\u8bf4\u7684\u4e0d\u4e25\u8c28\u554a\u3011<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u8bed\u6cd5<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>delegate(parameters) { statement; }<\/code><\/pre>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delegate void NumberChanger(int n);\n...\nNumberChanger nc = delegate(int x)\n{\n    Console.WriteLine(\"Anonymous Method: {0}\", x);\n};<\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\u5757&nbsp;<strong>Console.WriteLine(&#8220;Anonymous Method: {0}&#8221;, x);<\/strong>&nbsp;\u662f\u533f\u540d\u65b9\u6cd5\u7684\u4e3b\u4f53\u3002<\/p>\n\n\n\n<p><strong>\u59d4\u6258\u53ef\u4ee5\u901a\u8fc7\u533f\u540d\u65b9\u6cd5\u8c03\u7528\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u540d\u65b9\u6cd5\u8c03\u7528\uff0c\u5373\uff0c\u901a\u8fc7\u5411\u59d4\u6258\u5bf9\u8c61\u4f20\u9012\u65b9\u6cd5\u53c2\u6570\u3002<\/strong><\/p>\n\n\n\n<p><strong>\u6ce8\u610f:<\/strong>\u00a0\u533f\u540d\u65b9\u6cd5\u7684\u4e3b\u4f53\u540e\u9762\u9700\u8981\u4e00\u4e2a\u00a0<strong>;<\/strong> \u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nc(10);<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u793a\u4f8b\uff1a\u4f7f\u7528\u533f\u540d\u65b9\u6cd5\u5b9a\u4e49\u4e00\u4e2a\u59d4\u6258\nFunc&lt;int, int, int> multiply = delegate (int a, int b)\n{\n    return a * b;\n};\nConsole.WriteLine(multiply(2, 3)); \/\/ \u8f93\u51fa 6\n\n\/\/ \u793a\u4f8b\uff1a\u4f7f\u7528\u533f\u540d\u65b9\u6cd5\u4f5c\u4e3a\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\nButton button = new Button();\nbutton.Click += delegate (object sender, EventArgs e)\n{\n    Console.WriteLine(\"Button clicked!\");\n};<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u533f\u540d\u65b9\u6cd5\u7684\u6982\u5ff5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\ndelegate void NumberChanger(int n);\nnamespace DelegateAppl\n{\n    class TestDelegate\n    {\n        static int num = 10;\n        public static void AddNum(int p)\n        {\n            num += p;\n            Console.WriteLine(\"Named Method: {0}\", num);\n        }\n\n        public static void MultNum(int q)\n        {\n            num *= q;\n            Console.WriteLine(\"Named Method: {0}\", num);\n        }\n\n        static void Main(string&#91;] args)\n        {\n            \/\/ \u4f7f\u7528\u533f\u540d\u65b9\u6cd5\u521b\u5efa\u59d4\u6258\u5b9e\u4f8b\n            NumberChanger nc = delegate(int x)\n            {\n               Console.WriteLine(\"Anonymous Method: {0}\", x);\n            };\n           \n            \/\/ \u4f7f\u7528\u533f\u540d\u65b9\u6cd5\u8c03\u7528\u59d4\u6258\n            nc(10);\n\n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u5b9e\u4f8b\u5316\u59d4\u6258\n            nc =  new NumberChanger(AddNum);\n           \n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u8c03\u7528\u59d4\u6258\n            nc(5);\n\n            \/\/ \u4f7f\u7528\u53e6\u4e00\u4e2a\u547d\u540d\u65b9\u6cd5\u5b9e\u4f8b\u5316\u59d4\u6258\n            nc =  new NumberChanger(MultNum);\n           \n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u8c03\u7528\u59d4\u6258\n            nc(2);\n            Console.ReadKey();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p>\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\n\n\n<pre class=\"wp-block-code\"><code>Anonymous Method: 10\nNamed Method: 15\nNamed Method: 30<\/code><\/pre>\n\n\n\n<p>\u5728 C# 2.0 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0c\u5f15\u5165\u4e86 lambda \u8868\u8fbe\u5f0f\uff0c\u5b83\u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u8bed\u6cd5\u5f62\u5f0f\uff0c\u7528\u4e8e\u7f16\u5199\u533f\u540d\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;\n\ndelegate void NumberChanger(int n);\n\nnamespace DelegateAppl\n{\n    class TestDelegate\n    {\n        static int num = 10;\n\n        public static void AddNum(int p)\n        {\n            num += p;\n            Console.WriteLine(\"Named Method: {0}\", num);\n        }\n\n        public static void MultNum(int q)\n        {\n            num *= q;\n            Console.WriteLine(\"Named Method: {0}\", num);\n        }\n\n        static void Main(string&#91;] args)\n        {\n            \/\/ \u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u521b\u5efa\u59d4\u6258\u5b9e\u4f8b\n            NumberChanger nc = x => Console.WriteLine($\"Lambda Expression: {x}\");\n\n            \/\/ \u4f7f\u7528 lambda \u8868\u8fbe\u5f0f\u8c03\u7528\u59d4\u6258\n            nc(10);\n\n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u5b9e\u4f8b\u5316\u59d4\u6258\n            nc = new NumberChanger(AddNum);\n\n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u8c03\u7528\u59d4\u6258\n            nc(5);\n\n            \/\/ \u4f7f\u7528\u53e6\u4e00\u4e2a\u547d\u540d\u65b9\u6cd5\u5b9e\u4f8b\u5316\u59d4\u6258\n            nc = new NumberChanger(MultNum);\n\n            \/\/ \u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u8c03\u7528\u59d4\u6258\n            nc(2);\n\n            Console.ReadKey();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u611f\u89c9\u5b9e\u4f8b\u4e2d\u6ce8\u91ca\u6709\u70b9\u8ba9\u4eba\u7ed5 \uff0c\u4e2a\u4eba\u7406\u89e3\u662f\u59d4\u6258\u53bb\u8c03\u7528\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u6709\u4e00\u4e2a\u59d4\u6258\u4e2d\u5e26\u6709\u4e00\u4e2a\u65b9\u6cd5A\uff0c\u4e4b\u540e\u5c06\u59d4\u6258\u53d8\u91cf\u4f20\u9012\u7ed9\u4e00\u4e2a\u65b9\u6cd5B\uff08\u6216\u51fd\u6570\uff09 \uff0c\u7136\u540e\u51fd\u6570B\u5728\u6267\u884c\u7684\u65f6\u5019\uff0c\u4f1a\u901a\u8fc7\u59d4\u6258\u53bb\u8c03\u7528\u65b9\u6cd5A \u3002\u4f46\u6ce8\u91ca\u4e2d\u8ba9\u6211\u7406\u89e3\u4e3a\u662f\u65b9\u6cd5A\u53bb\u8c03\u7528\u7684\u59d4\u6258\uff0c\u8fd9\u4e2a\u6709\u70b9\u8d39\u89e3\uff0c\u5982\u679c\u8fd9\u8fb9\u7406\u4e0d\u6e05\uff0c\u4e8b\u4ef6\u90a3\u8fb9\u53ef\u80fd\u4f1a\u6709\u70b9\u4e71\u3002<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u8fd8\u6709\u672c\u7ae0\u4e2d\u533f\u540d\u65b9\u6cd5\u7684\u5b9a\u4e49\u662f\u6ca1\u6709\u540d\u79f0\u53ea\u6709\u65b9\u6cd5\u4e3b\u4f53\uff0c \u6240\u4ee5\u901a\u8fc7\u533f\u540d\u65b9\u6cd5\u53bb\u8c03\u7528\u59d4\u6258\u4e5f\u6709\u70b9\u7275\u5f3a\uff0c\u603b\u4e0d\u80fd\u662f\u65b9\u6cd5\u4f53\u53bb\u8c03\u7528\u59d4\u6258\u5427\uff0c\u8ba9\u59d4\u6258\u5e72\u5565\uff0c\u59d4\u6258\u5e94\u8be5\u6709\u70b9\u61f5\u903c\u3002<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u5173\u4e8e\u533f\u540d\u65b9\u6cd5\u8fd9\u5757\u513f\u6211\u7684\u7406\u89e3\u662f\uff1a\u7531\u4e8e\u533f\u540d\u65b9\u6cd5\u6ca1\u6709\u65b9\u6cd5\u7b7e\u540d\uff0c\u53ea\u6709\u65b9\u6cd5\u4f53\uff0c\u6240\u4ee5\u65e0\u6cd5\u4f7f\u7528\u547d\u540d\u65b9\u6cd5\u7c7b\u4f3c\u7684&nbsp;<strong>\u65b9\u6cd5\u540d();<\/strong>&nbsp;\u53bb\u8c03\u7528\uff0c\u6240\u4ee5\u53ea\u80fd\u5c06\u7531\u59d4\u6258\u53d8\u91cf\u53bb\u8c03\u7528\u5b83\uff0c\u6362\u8a00\u4e4b\uff0c\u533f\u540d\u65b9\u6cd5\u5c06\u81ea\u5df1\u552f\u4e00\u62e5\u6709\u7684\u65b9\u6cd5\u4e3b\u4f53\u4ea4\u7ed9\u59d4\u6258\uff0c\u8ba9\u59d4\u6258\u4ee3\u7406\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u4ee5\u4e0a\u4ec5\u662f\u4e2a\u4eba\u7406\u89e3\uff0c\u4f46\u611f\u89c9\u8fd9\u4e48\u7406\u89e3\u6bd4\u8f83\u5bb9\u6613\u63a5\u53d7\uff0c\u521a\u5165\u95e8\u5b66\u4e60\uff0c\u5982\u7406\u89e3\u4e0a\u6709\u8bef\u8fd8\u8bf7\u6307\u6559<\/p>\n\n\n\n<p><a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-anonymous-methods\/\">https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-anonymous-methods\/<\/a><\/p>\n\n\n\n<p>When assigning a method to a\u00a0<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-delegate\/\">delegate<\/a>, you define a method, either instance method or\u00a0<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-static-method\/\">static method<\/a>, and then assign it to the delegate. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Program\n{\n    delegate int Transfomer(int x);\n    static int Square(int x)\n    {\n        return x * x;\n    }\n    public static void Main(string&#91;] args)\n    {\n        Transfomer transform = Square;\n\n        Console.WriteLine(transform(10)); \/\/ 100\n    }\n}<\/code><\/pre>\n\n\n\n<p>In this example:<\/p>\n\n\n\n<p>First, declare a delegate called\u00a0<code>Transformer<\/code>\u00a0that accepts an integer and returns an integer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delegate int Transfomer(int x);<\/code><\/pre>\n\n\n\n<p>Second, define a static method called\u00a0<code>Square()<\/code>\u00a0with the same signature as the\u00a0<code>Transformer<\/code>\u00a0delegate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static int Square(int x)\n{\n    return x * x;\n}<\/code><\/pre>\n\n\n\n<p>Third, assign the\u00a0<code>Square<\/code>\u00a0method to the\u00a0<code>Transformer<\/code>\u00a0delegate and invoke it inside the\u00a0<code>Main()<\/code>\u00a0method:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Transfomer transform = Square;\nConsole.WriteLine(transform(10)); \/\/ 100<\/code><\/pre>\n\n\n\n<p>Sometimes, defining a new method is not necessary because you only use it once. It creates unwanted overhead.<\/p>\n\n\n\n<p>C# allows you to create a delegate and immediately assign a code block to it. This code block can be either an anonymous method or a&nbsp;<a href=\"https:\/\/www.csharptutorial.net\/csharp-tutorial\/csharp-lambda-expression\/\">lambda expression<\/a>.<\/p>\n\n\n\n<p>An anonymous method uses the&nbsp;<code>delegate<\/code>&nbsp;keyword followed by an optional parameter declaration and method body. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Program\n{\n    delegate int Transfomer(int x);\n\n    public static void Main(string&#91;] args)\n    {\n        Transfomer transform = delegate (int x) { return x * x; };\n\n        Console.WriteLine(transform(10)); \/\/ 100\n    }\n}<\/code><\/pre>\n\n\n\n<p>In this example, we don\u2019t define the static method&nbsp;<code>Square<\/code>. Instead, we assign an anonymous method to the&nbsp;<code>transform<\/code>&nbsp;delegate.<\/p>\n\n\n\n<p>The following statement defines an anonymous method and assigns it to the&nbsp;<code>Transformer<\/code>&nbsp;delegate:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>delegate (int x) { return x * x; }<\/code><\/pre>\n\n\n\n<p>Anonymous methods can access the outer variables. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class Program\n{\n    delegate decimal Pricing(decimal price);\n\n    public static void Main(string&#91;] args)\n    {\n        decimal tax = 0.08m;\n        decimal price = 100m;\n\n        Pricing calculateNet = delegate(decimal price) {\n            return price * (1 + tax);\n        };\n\n        Console.WriteLine(calculateNet(price));\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>108<\/code><\/pre>\n\n\n\n<p>In this example, the anonymous method accesses the&nbsp;<code>tax<\/code>&nbsp;variable from the&nbsp;<code>Main()<\/code>&nbsp;method.<\/p>\n\n\n\n<p>Starting from C# 3, you can use lambda expressions instead of anonymous methods, which have more concise syntax.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul>\n<li>Anonymous methods are methods without names.<\/li>\n\n\n\n<li>Use the\u00a0<code>delegate<\/code>\u00a0keyword to define an anonymous method.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>C# Generics Introduction to the C# generics \u3010\u6cdb\u578b\u65b9\u6cd5\u3011 C# g&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1507,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[60],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"C# Generics Introduction to the C# generics \u3010\u6cdb\u578b\u65b9\u6cd5\u3011 C# g...\" \/>\n<meta property=\"og:url\" content=\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\/\" \/>\n<meta property=\"og:site_name\" content=\"\u7801\u5148\u751f\u7684\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-09T16:40:19+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/csharp1-\u526f\u672c-3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"489\" \/>\n\t<meta property=\"og:image:height\" content=\"468\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"\u7801\u5148\u751f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/mrcode2021\" \/>\n<meta name=\"twitter:site\" content=\"@mrcode2021\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u7801\u5148\u751f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/\"},\"author\":{\"name\":\"\u7801\u5148\u751f\",\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"headline\":\"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\",\"datePublished\":\"2025-03-09T16:40:19+00:00\",\"dateModified\":\"2025-03-09T16:40:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/\"},\"wordCount\":704,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"keywords\":[\"csharp\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/\",\"url\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/\",\"name\":\"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"http:\/\/codermr.com\/#website\"},\"datePublished\":\"2025-03-09T16:40:19+00:00\",\"dateModified\":\"2025-03-09T16:40:19+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/codermr.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/codermr.com\/#website\",\"url\":\"http:\/\/codermr.com\/\",\"name\":\"\u7801\u5148\u751f\u7684\u535a\u5ba2\",\"description\":\"\u6b22 \u8fce \u4e0b \u8f7d \u6211 \u5f00 \u53d1 \u7684 \u5404 \u7aef \u8f6f \u4ef6 \u548c APP\",\"publisher\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/codermr.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf\",\"name\":\"\u7801\u5148\u751f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg\",\"contentUrl\":\"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg\",\"width\":400,\"height\":400,\"caption\":\"\u7801\u5148\u751f\"},\"logo\":{\"@id\":\"http:\/\/codermr.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/codermr.com\",\"https:\/\/twitter.com\/https:\/\/twitter.com\/mrcode2021\"],\"url\":\"http:\/\/codermr.com\/index.php\/author\/coderma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2","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":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\/","og_locale":"zh_CN","og_type":"article","og_title":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2","og_description":"C# Generics Introduction to the C# generics \u3010\u6cdb\u578b\u65b9\u6cd5\u3011 C# g...","og_url":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5\/","og_site_name":"\u7801\u5148\u751f\u7684\u535a\u5ba2","article_published_time":"2025-03-09T16:40:19+00:00","og_image":[{"width":489,"height":468,"url":"http:\/\/codermr.com\/wp-content\/uploads\/2025\/03\/csharp1-\u526f\u672c-3.png","type":"image\/png"}],"author":"\u7801\u5148\u751f","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/mrcode2021","twitter_site":"@mrcode2021","twitter_misc":{"\u4f5c\u8005":"\u7801\u5148\u751f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#article","isPartOf":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/"},"author":{"name":"\u7801\u5148\u751f","@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"headline":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5","datePublished":"2025-03-09T16:40:19+00:00","dateModified":"2025-03-09T16:40:19+00:00","mainEntityOfPage":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/"},"wordCount":704,"commentCount":0,"publisher":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"keywords":["csharp"],"articleSection":["C#"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/","url":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/","name":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5 - \u7801\u5148\u751f\u7684\u535a\u5ba2","isPartOf":{"@id":"http:\/\/codermr.com\/#website"},"datePublished":"2025-03-09T16:40:19+00:00","dateModified":"2025-03-09T16:40:19+00:00","breadcrumb":{"@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/codermr.com\/index.php\/2025\/03\/10\/c%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%b1%87%e6%80%bb%e4%b8%83%ef%bc%9a%e6%b3%9b%e5%9e%8b%e3%80%81%e5%8c%bf%e5%90%8d%e6%96%b9%e6%b3%95\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/codermr.com\/"},{"@type":"ListItem","position":2,"name":"C#\u57fa\u7840\u77e5\u8bc6\u6c47\u603b\u4e03\uff1a\u6cdb\u578b\u3001\u533f\u540d\u65b9\u6cd5"}]},{"@type":"WebSite","@id":"http:\/\/codermr.com\/#website","url":"http:\/\/codermr.com\/","name":"\u7801\u5148\u751f\u7684\u535a\u5ba2","description":"\u6b22 \u8fce \u4e0b \u8f7d \u6211 \u5f00 \u53d1 \u7684 \u5404 \u7aef \u8f6f \u4ef6 \u548c APP","publisher":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/codermr.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/codermr.com\/#\/schema\/person\/39016e15c79e4f02d1ed3a64688619bf","name":"\u7801\u5148\u751f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/codermr.com\/#\/schema\/person\/image\/","url":"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg","contentUrl":"http:\/\/codermr.com\/wp-content\/uploads\/2023\/02\/wukong.jpg","width":400,"height":400,"caption":"\u7801\u5148\u751f"},"logo":{"@id":"http:\/\/codermr.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/codermr.com","https:\/\/twitter.com\/https:\/\/twitter.com\/mrcode2021"],"url":"http:\/\/codermr.com\/index.php\/author\/coderma\/"}]}},"_links":{"self":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1503"}],"collection":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/comments?post=1503"}],"version-history":[{"count":7,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1503\/revisions"}],"predecessor-version":[{"id":1514,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/posts\/1503\/revisions\/1514"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/media\/1507"}],"wp:attachment":[{"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/media?parent=1503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/categories?post=1503"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/codermr.com\/index.php\/wp-json\/wp\/v2\/tags?post=1503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}