{"id":236245,"date":"2022-03-01T10:39:30","date_gmt":"2022-03-01T02:39:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=236245"},"modified":"2022-02-21T15:40:23","modified_gmt":"2022-02-21T07:40:23","slug":"the-c-method","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/the-c-method.html","title":{"rendered":"\u4e86\u89e3\u4e0bC# \u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e00\u4e2a\u65b9\u6cd5\u662f\u628a\u4e00\u4e9b\u76f8\u5173\u7684\u8bed\u53e5\u7ec4\u7ec7\u5728\u4e00\u8d77\uff0c\u7528\u6765\u6267\u884c\u4e00\u4e2a\u4efb\u52a1\u7684\u8bed\u53e5\u5757\u3002\u6bcf\u4e00\u4e2a C# \u7a0b\u5e8f\u81f3\u5c11\u6709\u4e00\u4e2a\u5e26\u6709 Main \u65b9\u6cd5\u7684\u7c7b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u8981\u4f7f\u7528\u4e00\u4e2a\u65b9\u6cd5\uff0c\u60a8\u9700\u8981\uff1a<\/p>\n

    \n
  1. \u5b9a\u4e49\u65b9\u6cd5<\/li>\n
  2. \u8c03\u7528\u65b9\u6cd5<\/li>\n<\/ol>\n
    C# \u4e2d\u5b9a\u4e49\u65b9\u6cd5<\/strong><\/div>\n

    \u5f53\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u4ece\u6839\u672c\u4e0a\u8bf4\u662f\u5728\u58f0\u660e\u5b83\u7684\u7ed3\u6784\u7684\u5143\u7d20\u3002\u5728 C# \u4e2d\uff0c\u5b9a\u4e49\u65b9\u6cd5\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n

      (Parameter List)\r\n{\r\n   Method Body\r\n}<\/method><\/return><\/access><\/pre>\n

    \u4e0b\u9762\u662f\u65b9\u6cd5\u7684\u5404\u4e2a\u5143\u7d20\uff1a<\/p>\n

      \n
    1. Access Specifier\uff1a\u8bbf\u95ee\u4fee\u9970\u7b26\uff0c\u8fd9\u4e2a\u51b3\u5b9a\u4e86\u53d8\u91cf\u6216\u65b9\u6cd5\u5bf9\u4e8e\u53e6\u4e00\u4e2a\u7c7b\u7684\u53ef\u89c1\u6027\u3002<\/li>\n
    2. Return type\uff1a\u8fd4\u56de\u7c7b\u578b\uff0c\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u8fd4\u56de\u7c7b\u578b\u662f\u65b9\u6cd5\u8fd4\u56de\u7684\u503c\u7684\u6570\u636e\u7c7b\u578b\u3002\u5982\u679c\u65b9\u6cd5\u4e0d\u8fd4\u56de\u4efb\u4f55\u503c\uff0c\u5219\u8fd4\u56de\u7c7b\u578b\u4e3a void\u3002<\/li>\n
    3. Method name\uff1a\u65b9\u6cd5\u540d\u79f0\uff0c\u662f\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u4e14\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\u3002\u5b83\u4e0d\u80fd\u4e0e\u7c7b\u4e2d\u58f0\u660e\u7684\u5176\u4ed6\u6807\u8bc6\u7b26\u76f8\u540c\u3002<\/li>\n
    4. Parameter list\uff1a\u53c2\u6570\u5217\u8868\uff0c\u4f7f\u7528\u5706\u62ec\u53f7\u62ec\u8d77\u6765\uff0c\u8be5\u53c2\u6570\u662f\u7528\u6765\u4f20\u9012\u548c\u63a5\u6536\u65b9\u6cd5\u7684\u6570\u636e\u3002\u53c2\u6570\u5217\u8868\u662f\u6307\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b\u3001\u987a\u5e8f\u548c\u6570\u91cf\u3002\u53c2\u6570\u662f\u53ef\u9009\u7684\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u4e00\u4e2a\u65b9\u6cd5\u53ef\u80fd\u4e0d\u5305\u542b\u53c2\u6570\u3002<\/li>\n
    5. Method body\uff1a\u65b9\u6cd5\u4e3b\u4f53\uff0c\u5305\u542b\u4e86\u5b8c\u6210\u4efb\u52a1\u6240\u9700\u7684\u6307\u4ee4\u96c6\u3002<\/li>\n<\/ol>\n
      \u5b9e\u4f8b
      \n<\/strong><\/div>\n

      \u4e0b\u9762\u7684\u4ee3\u7801\u7247\u6bb5\u663e\u793a\u4e00\u4e2a\u51fd\u6570 FindMax\uff0c\u5b83\u63a5\u53d7\u4e24\u4e2a\u6574\u6570\u503c\uff0c\u5e76\u8fd4\u56de\u4e24\u4e2a\u4e2d\u7684\u8f83\u5927\u503c\u3002\u5b83\u6709 public \u8bbf\u95ee\u4fee\u9970\u7b26\uff0c\u6240\u4ee5\u5b83\u53ef\u4ee5\u4f7f\u7528\u7c7b\u7684\u5b9e\u4f8b\u4ece\u7c7b\u7684\u5916\u90e8\u8fdb\u884c\u8bbf\u95ee\u3002
      \n\u5b9e\u4f8b<\/p>\n

      class NumberManipulator\r\n{\r\n   public int FindMax(int num1, int num2)\r\n   {\r\n      \/* \u5c40\u90e8\u53d8\u91cf\u58f0\u660e *\/\r\n      int result;\r\n\r\n      if (num1 > num2)\r\n         result = num1;\r\n      else\r\n         result = num2;\r\n\r\n      return result;\r\n   }\r\n   ...\r\n}<\/pre>\n
      C# \u4e2d\u8c03\u7528\u65b9\u6cd5<\/strong><\/div>\n

      \u60a8\u53ef\u4ee5\u4f7f\u7528\u65b9\u6cd5\u540d\u8c03\u7528\u65b9\u6cd5\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u8fd9\u70b9\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n   class NumberManipulator\r\n   {\r\n      public int FindMax(int num1, int num2)\r\n      {\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u58f0\u660e *\/\r\n         int result;\r\n\r\n         if (num1 > num2)\r\n            result = num1;\r\n         else\r\n            result = num2;\r\n\r\n         return result;\r\n      }\r\n      static void Main(string[] args)\r\n      {\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n         int a = 100;\r\n         int b = 200;\r\n         int ret;\r\n         NumberManipulator n = new NumberManipulator();\r\n\r\n         \/\/\u8c03\u7528 FindMax \u65b9\u6cd5\r\n         ret = n.FindMax(a, b);\r\n         Console.WriteLine(\"\u6700\u5927\u503c\u662f\uff1a {0}\", ret );\r\n         Console.ReadLine();\r\n      }\r\n   }\r\n}<\/pre>\n

      \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

      \u6700\u5927\u503c\u662f\uff1a 200<\/pre>\n

      \u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u7c7b\u7684\u5b9e\u4f8b\u4ece\u53e6\u4e00\u4e2a\u7c7b\u4e2d\u8c03\u7528\u5176\u4ed6\u7c7b\u7684\u516c\u6709\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u65b9\u6cd5 FindMax \u5c5e\u4e8e NumberManipulator \u7c7b\uff0c\u60a8\u53ef\u4ee5\u4ece\u53e6\u4e00\u4e2a\u7c7b Test \u4e2d\u8c03\u7528\u5b83\u3002<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n    class NumberManipulator\r\n    {\r\n        public int FindMax(int num1, int num2)\r\n        {\r\n            \/* \u5c40\u90e8\u53d8\u91cf\u58f0\u660e *\/\r\n            int result;\r\n\r\n            if (num1 > num2)\r\n                result = num1;\r\n            else\r\n                result = num2;\r\n\r\n            return result;\r\n        }\r\n    }\r\n    class Test\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n            int a = 100;\r\n            int b = 200;\r\n            int ret;\r\n            NumberManipulator n = new NumberManipulator();\r\n            \/\/\u8c03\u7528 FindMax \u65b9\u6cd5\r\n            ret = n.FindMax(a, b);\r\n            Console.WriteLine(\"\u6700\u5927\u503c\u662f\uff1a {0}\", ret );\r\n            Console.ReadLine();\r\n\r\n        }\r\n    }\r\n}<\/pre>\n

      \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

      \u6700\u5927\u503c\u662f\uff1a 200<\/pre>\n
      \u9012\u5f52\u65b9\u6cd5\u8c03\u7528<\/strong><\/div>\n

      \u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u81ea\u6211\u8c03\u7528\u3002\u8fd9\u5c31\u662f\u6240\u8c13\u7684 \u9012\u5f52\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u8ba1\u7b97\u4e00\u4e2a\u6570\u7684\u9636\u4e58\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n    class NumberManipulator\r\n    {\r\n        public int factorial(int num)\r\n        {\r\n            \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n            int result;\r\n\r\n            if (num == 1)\r\n            {\r\n                return 1;\r\n            }\r\n            else\r\n            {\r\n                result = factorial(num - 1) * num;\r\n                return result;\r\n            }\r\n        }\r\n   \r\n        static void Main(string[] args)\r\n        {\r\n            NumberManipulator n = new NumberManipulator();\r\n            \/\/\u8c03\u7528 factorial \u65b9\u6cd5\r\n            Console.WriteLine(\"6 \u7684\u9636\u4e58\u662f\uff1a {0}\", n.factorial(6));\r\n            Console.WriteLine(\"7 \u7684\u9636\u4e58\u662f\uff1a {0}\", n.factorial(7));\r\n            Console.WriteLine(\"8 \u7684\u9636\u4e58\u662f\uff1a {0}\", n.factorial(8));\r\n            Console.ReadLine();\r\n\r\n        }\r\n    }\r\n}<\/pre>\n

      \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

      6 \u7684\u9636\u4e58\u662f\uff1a 720\r\n7 \u7684\u9636\u4e58\u662f\uff1a 5040\r\n8 \u7684\u9636\u4e58\u662f\uff1a 40320<\/pre>\n
      \u53c2\u6570\u4f20\u9012<\/strong><\/div>\n

      \u5f53\u8c03\u7528\u5e26\u6709\u53c2\u6570\u7684\u65b9\u6cd5\u65f6\uff0c\u60a8\u9700\u8981\u5411\u65b9\u6cd5\u4f20\u9012\u53c2\u6570\u3002\u5728 C# \u4e2d\uff0c\u6709\u4e09\u79cd\u5411\u65b9\u6cd5\u4f20\u9012\u53c2\u6570\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n\n\n\n
      \u65b9\u5f0f<\/th>\n\u63cf\u8ff0<\/th>\n<\/tr>\n
      \u503c\u53c2\u6570<\/td>\n\u8fd9\u79cd\u65b9\u5f0f\u590d\u5236\u53c2\u6570\u7684\u5b9e\u9645\u503c\u7ed9\u51fd\u6570\u7684\u5f62\u5f0f\u53c2\u6570\uff0c\u5b9e\u53c2\u548c\u5f62\u53c2\u4f7f\u7528\u7684\u662f\u4e24\u4e2a\u4e0d\u540c\u5185\u5b58\u4e2d\u7684\u503c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f53\u5f62\u53c2\u7684\u503c\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5b9e\u53c2\u7684\u503c\uff0c\u4ece\u800c\u4fdd\u8bc1\u4e86\u5b9e\u53c2\u6570\u636e\u7684\u5b89\u5168\u3002<\/td>\n<\/tr>\n
      \u5f15\u7528\u53c2\u6570<\/td>\n\u8fd9\u79cd\u65b9\u5f0f\u590d\u5236\u53c2\u6570\u7684\u5185\u5b58\u4f4d\u7f6e\u7684\u5f15\u7528\u7ed9\u5f62\u5f0f\u53c2\u6570\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5f53\u5f62\u53c2\u7684\u503c\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u540c\u65f6\u4e5f\u6539\u53d8\u5b9e\u53c2\u7684\u503c\u3002<\/td>\n<\/tr>\n
      \u8f93\u51fa\u53c2\u6570<\/td>\n\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u503c\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
      \u6309\u503c\u4f20\u9012\u53c2\u6570<\/strong><\/div>\n

      \u8fd9\u662f\u53c2\u6570\u4f20\u9012\u7684\u9ed8\u8ba4\u65b9\u5f0f\u3002\u5728\u8fd9\u79cd\u65b9\u5f0f\u4e0b\uff0c\u5f53\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u4f1a\u4e3a\u6bcf\u4e2a\u503c\u53c2\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002<\/p>\n

      \u5b9e\u9645\u53c2\u6570\u7684\u503c\u4f1a\u590d\u5236\u7ed9\u5f62\u53c2\uff0c\u5b9e\u53c2\u548c\u5f62\u53c2\u4f7f\u7528\u7684\u662f\u4e24\u4e2a\u4e0d\u540c\u5185\u5b58\u4e2d\u7684\u503c\u3002\u6240\u4ee5\uff0c\u5f53\u5f62\u53c2\u7684\u503c\u53d1\u751f\u6539\u53d8\u65f6\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5b9e\u53c2\u7684\u503c\uff0c\u4ece\u800c\u4fdd\u8bc1\u4e86\u5b9e\u53c2\u6570\u636e\u7684\u5b89\u5168\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u8fd9\u4e2a\u6982\u5ff5\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n   class NumberManipulator\r\n   {\r\n      public void swap(int x, int y)\r\n      {\r\n         int temp;\r\n         \r\n         temp = x; \/* \u4fdd\u5b58 x \u7684\u503c *\/\r\n         x = y;    \/* \u628a y \u8d4b\u503c\u7ed9 x *\/\r\n         y = temp; \/* \u628a temp \u8d4b\u503c\u7ed9 y *\/\r\n      }\r\n     \r\n      static void Main(string[] args)\r\n      {\r\n         NumberManipulator n = new NumberManipulator();\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n         int a = 100;\r\n         int b = 200;\r\n         \r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u524d\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u524d\uff0cb \u7684\u503c\uff1a {0}\", b);\r\n         \r\n         \/* \u8c03\u7528\u51fd\u6570\u6765\u4ea4\u6362\u503c *\/\r\n         n.swap(a, b);\r\n         \r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u540e\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u540e\uff0cb \u7684\u503c\uff1a {0}\", b);\r\n         \r\n         Console.ReadLine();\r\n      }\r\n   }\r\n}<\/pre>\n

      \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

      \u5728\u4ea4\u6362\u4e4b\u524d\uff0ca \u7684\u503c\uff1a100\r\n\u5728\u4ea4\u6362\u4e4b\u524d\uff0cb \u7684\u503c\uff1a200\r\n\u5728\u4ea4\u6362\u4e4b\u540e\uff0ca \u7684\u503c\uff1a100\r\n\u5728\u4ea4\u6362\u4e4b\u540e\uff0cb \u7684\u503c\uff1a200<\/pre>\n

      \u7ed3\u679c\u8868\u660e\uff0c\u5373\u4f7f\u5728\u51fd\u6570\u5185\u6539\u53d8\u4e86\u503c\uff0c\u503c\u4e5f\u6ca1\u6709\u53d1\u751f\u4efb\u4f55\u7684\u53d8\u5316\u3002<\/p>\n

      \u6309\u5f15\u7528\u4f20\u9012\u53c2\u6570<\/strong><\/div>\n

      \u5f15\u7528\u53c2\u6570\u662f\u4e00\u4e2a\u5bf9\u53d8\u91cf\u7684\u5185\u5b58\u4f4d\u7f6e\u7684\u5f15\u7528\u3002\u5f53\u6309\u5f15\u7528\u4f20\u9012\u53c2\u6570\u65f6\uff0c\u4e0e\u503c\u53c2\u6570\u4e0d\u540c\u7684\u662f\uff0c\u5b83\u4e0d\u4f1a\u4e3a\u8fd9\u4e9b\u53c2\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b58\u50a8\u4f4d\u7f6e\u3002\u5f15\u7528\u53c2\u6570\u8868\u793a\u4e0e\u63d0\u4f9b\u7ed9\u65b9\u6cd5\u7684\u5b9e\u9645\u53c2\u6570\u5177\u6709\u76f8\u540c\u7684\u5185\u5b58\u4f4d\u7f6e\u3002<\/p>\n

      \u5728 C# \u4e2d\uff0c\u4f7f\u7528 ref \u5173\u952e\u5b57\u58f0\u660e\u5f15\u7528\u53c2\u6570\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u8fd9\u70b9\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n   class NumberManipulator\r\n   {\r\n      public void swap(ref int x, ref int y)\r\n      {\r\n         int temp;\r\n\r\n         temp = x; \/* \u4fdd\u5b58 x \u7684\u503c *\/\r\n         x = y;    \/* \u628a y \u8d4b\u503c\u7ed9 x *\/\r\n         y = temp; \/* \u628a temp \u8d4b\u503c\u7ed9 y *\/\r\n       }\r\n   \r\n      static void Main(string[] args)\r\n      {\r\n         NumberManipulator n = new NumberManipulator();\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n         int a = 100;\r\n         int b = 200;\r\n\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u524d\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u524d\uff0cb \u7684\u503c\uff1a {0}\", b);\r\n\r\n         \/* \u8c03\u7528\u51fd\u6570\u6765\u4ea4\u6362\u503c *\/\r\n         n.swap(ref a, ref b);\r\n\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u540e\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.WriteLine(\"\u5728\u4ea4\u6362\u4e4b\u540e\uff0cb \u7684\u503c\uff1a {0}\", b);\r\n \r\n         Console.ReadLine();\r\n\r\n      }\r\n   }\r\n}<\/pre>\n

      \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

      \u5728\u4ea4\u6362\u4e4b\u524d\uff0ca \u7684\u503c\uff1a100\r\n\u5728\u4ea4\u6362\u4e4b\u524d\uff0cb \u7684\u503c\uff1a200\r\n\u5728\u4ea4\u6362\u4e4b\u540e\uff0ca \u7684\u503c\uff1a200\r\n\u5728\u4ea4\u6362\u4e4b\u540e\uff0cb \u7684\u503c\uff1a100<\/pre>\n

      \u7ed3\u679c\u8868\u660e\uff0cswap \u51fd\u6570\u5185\u7684\u503c\u6539\u53d8\u4e86\uff0c\u4e14\u8fd9\u4e2a\u6539\u53d8\u53ef\u4ee5\u5728 Main \u51fd\u6570\u4e2d\u53cd\u6620\u51fa\u6765\u3002<\/p>\n

      \u6309\u8f93\u51fa\u4f20\u9012\u53c2\u6570<\/strong><\/div>\n

      return \u8bed\u53e5\u53ef\u7528\u4e8e\u53ea\u4ece\u51fd\u6570\u4e2d\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u4f46\u662f\uff0c\u53ef\u4ee5\u4f7f\u7528 \u8f93\u51fa\u53c2\u6570 \u6765\u4ece\u51fd\u6570\u4e2d\u8fd4\u56de\u4e24\u4e2a\u503c\u3002\u8f93\u51fa\u53c2\u6570\u4f1a\u628a\u65b9\u6cd5\u8f93\u51fa\u7684\u6570\u636e\u8d4b\u7ed9\u81ea\u5df1\uff0c\u5176\u4ed6\u65b9\u9762\u4e0e\u5f15\u7528\u53c2\u6570\u76f8\u4f3c\u3002<\/p>\n

      \u4e0b\u9762\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u8fd9\u70b9\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n   class NumberManipulator\r\n   {\r\n      public void getValue(out int x )\r\n      {\r\n         int temp = 5;\r\n         x = temp;\r\n      }\r\n   \r\n      static void Main(string[] args)\r\n      {\r\n         NumberManipulator n = new NumberManipulator();\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n         int a = 100;\r\n         \r\n         Console.WriteLine(\"\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u524d\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         \r\n         \/* \u8c03\u7528\u51fd\u6570\u6765\u83b7\u53d6\u503c *\/\r\n         n.getValue(out a);\r\n\r\n         Console.WriteLine(\"\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.ReadLine();\r\n\r\n      }\r\n   }\r\n}<\/pre>\n

      \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

      \u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u524d\uff0ca \u7684\u503c\uff1a 100\r\n\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0ca \u7684\u503c\uff1a 5<\/pre>\n

      \u63d0\u4f9b\u7ed9\u8f93\u51fa\u53c2\u6570\u7684\u53d8\u91cf\u4e0d\u9700\u8981\u8d4b\u503c\u3002\u5f53\u9700\u8981\u4ece\u4e00\u4e2a\u53c2\u6570\u6ca1\u6709\u6307\u5b9a\u521d\u59cb\u503c\u7684\u65b9\u6cd5\u4e2d\u8fd4\u56de\u503c\u65f6\uff0c\u8f93\u51fa\u53c2\u6570\u7279\u522b\u6709\u7528\u3002\u8bf7\u770b\u4e0b\u9762\u7684\u5b9e\u4f8b\uff0c\u6765\u7406\u89e3\u8fd9\u4e00\u70b9\uff1a<\/p>\n

      \u5b9e\u4f8b<\/p>\n

      using System;\r\nnamespace CalculatorApplication\r\n{\r\n   class NumberManipulator\r\n   {\r\n      public void getValues(out int x, out int y )\r\n      {\r\n          Console.WriteLine(\"\u8bf7\u8f93\u5165\u7b2c\u4e00\u4e2a\u503c\uff1a \");\r\n          x = Convert.ToInt32(Console.ReadLine());\r\n          Console.WriteLine(\"\u8bf7\u8f93\u5165\u7b2c\u4e8c\u4e2a\u503c\uff1a \");\r\n          y = Convert.ToInt32(Console.ReadLine());\r\n      }\r\n   \r\n      static void Main(string[] args)\r\n      {\r\n         NumberManipulator n = new NumberManipulator();\r\n         \/* \u5c40\u90e8\u53d8\u91cf\u5b9a\u4e49 *\/\r\n         int a , b;\r\n         \r\n         \/* \u8c03\u7528\u51fd\u6570\u6765\u83b7\u53d6\u503c *\/\r\n         n.getValues(out a, out b);\r\n\r\n         Console.WriteLine(\"\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0ca \u7684\u503c\uff1a {0}\", a);\r\n         Console.WriteLine(\"\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0cb \u7684\u503c\uff1a {0}\", b);\r\n         Console.ReadLine();\r\n      }\r\n   }\r\n}<\/pre>\n

      \u5f53\u4e0a\u9762\u7684\u4ee3\u7801\u88ab\u7f16\u8bd1\u548c\u6267\u884c\u65f6\uff0c\u5b83\u4f1a\u4ea7\u751f\u4e0b\u5217\u7ed3\u679c\uff08\u53d6\u51b3\u4e8e\u7528\u6237\u8f93\u5165\uff09\uff1a<\/p>\n

      \u8bf7\u8f93\u5165\u7b2c\u4e00\u4e2a\u503c\uff1a\r\n7\r\n\u8bf7\u8f93\u5165\u7b2c\u4e8c\u4e2a\u503c\uff1a\r\n8\r\n\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0ca \u7684\u503c\uff1a 7\r\n\u5728\u65b9\u6cd5\u8c03\u7528\u4e4b\u540e\uff0cb \u7684\u503c\uff1a 8<\/pre>\n","protected":false},"excerpt":{"rendered":"

      \u8981\u4f7f\u7528\u4e00\u4e2a\u65b9\u6cd5\uff0c\u60a8\u9700\u8981\uff1a \u5b9a\u4e49\u65b9\u6cd5 \u8c03\u7528\u65b9\u6cd5 \u5f53\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\u65f6\uff0c\u4ece\u6839\u672c\u4e0a\u8bf4\u662f\u5728\u58f0\u660e\u5b83\u7684\u7ed3\u6784\u7684\u5143\u7d20\u3002\u5728 C# \u4e2d […]<\/p>\n","protected":false},"author":321,"featured_media":236247,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-236245","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/321"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=236245"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236245\/revisions"}],"predecessor-version":[{"id":236251,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/236245\/revisions\/236251"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/236247"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=236245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=236245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=236245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}