{"id":117,"date":"2002-04-24T09:29:00","date_gmt":"2002-04-24T01:29:00","guid":{"rendered":"http:\/\/www.freemindworld.com\/blog\/2002\/04\/0424_%e4%bd%93%e9%aa%8cmicrosoft-net-%e4%b8%8e%e5%88%9d%e5%ad%a6%e8%80%85%e4%b8%80%e8%b5%b7%e7%94%a8-net%e5%86%99%e7%8c%9c%e6%95%b0%e5%ad%97%e6%b8%b8%e6%88%8f.shtml"},"modified":"2012-02-02T19:06:35","modified_gmt":"2012-02-02T11:06:35","slug":"020424_experience_dotnet","status":"publish","type":"post","link":"https:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml","title":{"rendered":"\u4f53\u9a8cMicrosoft.NET&#8211;\u4e0e\u521d\u5b66\u8005\u4e00\u8d77\u7528.NET\u5199\u731c\u6570\u5b57\u6e38\u620f"},"content":{"rendered":"<p align=\"center\"><span style=\"font-size: 42pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8c<img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-928\" title=\".NET\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424A.jpg\" alt=\".NET\" width=\"115\" height=\"60\" \/><\/span><\/p>\n<p>\u5fae\u8f6f\u516c\u53f8\u6b63\u5728\u9886\u5bfc\u4e00\u6b21\u65b0\u7684\u4e92\u8054\u7f51\u6280\u672f\u9769\u547d\uff0c\u8fd9\u5c31\u662f.NET\u3002.NET\u662f\u4e00\u79cd\u5168\u65b0\u7684\u57fa\u4e8eInternet\u7684\u7f16\u7a0b\u6a21\u578b\u30022\u670813\u65e5\u5fae\u8f6f\u516c\u53f8\u5728\u7f8e\u56fd\u6b63\u5f0f\u53d1\u5e03\u4e86\u5168\u65b0\u7684\u57fa\u4e8e.NET\u5e73\u53f0\u7684\u5f00\u53d1\u5de5\u5177\u2014\u2014Visual Studio.NET\uff0c\u8fd9\u6807\u5fd7\u7740\u5fae\u8f6f.NET\u65f6\u4ee3\u7684\u5168\u9762\u5230\u6765\u3002<\/p>\n<p>\u6211\u60f3\u901a\u8fc7\u672c\u6587\uff0c\u548c\u5927\u5bb6\u4e00\u8d77\u7528.NET\u5f00\u53d1\u4e00\u4e2a\u7b80\u5355\u7684\u5c0f\u6e38\u620f\u2014\u2014\u731c\u6570\u5b57\uff0c\u4e0e\u5927\u5bb6\u4e00\u8d77\u5206\u4eab\u6211\u5728\u5b66\u4e60.NET\u6280\u672f\u4e2d\u7684\u4e00\u4e9b\u5fc3\u5f97\u4f53\u4f1a\uff0c\u5206\u4eab.NET\u5e26\u7ed9\u6211\u4eec\u7684\u5168\u65b0\u7684\u5f00\u53d1\u4f53\u9a8c\u3002<\/p>\n<p align=\"center\"><span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4b\u57fa\u7840\u7bc7<\/span><\/p>\n<p>\u4f5c\u4e3a\u4e00\u4e2a\u5168\u65b0\u7684\u5f00\u53d1\u5e73\u53f0\uff0c\u5728Visual Studio.NET\u53d1\u5e03\u4e4b\u524d\uff0c\u5fae\u8f6f\u516c\u53f8\u5df2\u7ecf\u6b63\u5f0f\u53d1\u5e03\u4e86.NET Framework\u7684SDK\uff0c\u8fd9\u662f\u6211\u4eec\u8fdb\u884c.NET\u5f00\u53d1\u7684\u57fa\u672c\u6761\u4ef6\u3002\u8fd9\u4e2a\u66fe\u7ecf\u88ab\u79f0\u4e3a\u662fNGWS\uff08Next Generation Windows Services\uff09\u7684SDK\u63d0\u4f9b\u7ed9\u4e86\u6211\u4eec\u5305\u62ecC#\uff08\u8bfb\u97f3\u4e3aC Sharp\uff09\u7f16\u8bd1\u5668\u3001VB\u7f16\u8bd1\u5668\u3001ASP.NET\u8fd0\u884c\u73af\u5883\u7b49\u4e00\u7cfb\u5217.NET\u652f\u6301\u5e73\u53f0\u548c\u76f8\u5173\u7684\u6587\u6863\u3002<\/p>\n<p>SDK\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5f00\u53d1\u5e73\u53f0\uff0c\u5982\u679c\u4f60\u5b89\u88c5\u4e86.NET Framework SDK\uff0c\u4f60\u5c31\u53ef\u4ee5\u5f00\u53d1\u4e00\u7cfb\u5217\u7684.NET\u5e94\u7528\uff0c\u4f46\u662f\u4f60\u5c06\u65e0\u6cd5\u5145\u5206\u4f53\u9a8c\u5230.NET\u5e26\u7ed9\u6211\u4eec\u7684\u5feb\u901f\u5f00\u53d1\u7684\u4e50\u8da3\uff0c\u4f60\u4ecd\u9700\u8981\u4f7f\u7528\u53e4\u8001\u7684MSDOS\u547d\u4ee4\u884c\u7684\u65b9\u5f0f\u6765\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\u3002\u56e0\u6b64\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5b89\u88c5Visual Studio.NET\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff0c\u6709\u4e86\u5b83\u6211\u4eec\u624d\u53ef\u4ee5\u771f\u6b63\u4f53\u9a8c\u5230.NET\u5f00\u53d1\u7684\u4e50\u8da3\u3002Visual Studio.NET\u4e2d\u6587\u6b63\u5f0f\u7248\u5df2\u4e8e3\u670822\u65e5\u6b63\u5f0f\u53d1\u5e03\u3002\u7531\u4e8e\u6761\u4ef6\u6240\u9650\uff0c\u672c\u6587\u4e2d\u4f7f\u7528\u7684Visual Studio.NET\u4e3a\u82f1\u6587\u6b63\u5f0f\u7248\uff0c\u4f46\u6240\u6d89\u53ca\u5230\u7684\u7a0b\u5e8f\u5747\u53ef\u4ee5\u5728\u4e2d\u6587\u6b63\u5f0f\u7248\u4e2d\u7f16\u8bd1\u8fd0\u884c\u3002<\/p>\n<p>Microsoft Visual Studio.NET\u662f\u4e13\u95e8\u5f00\u53d1\u57fa\u4e8e.NET\u5e73\u53f0\u5e94\u7528\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff0c\u5305\u62ecVisual Basic.NET\u3001Visual C++.NET\u548c\u6700\u65b0\u7684Visual C#.NET\u7b49\u4e00\u7cfb\u5217\u7684\u5f00\u53d1\u5de5\u5177\uff0c\u901a\u8fc7\u8fd9\u4e2a\u5f3a\u5927\u7684\u5f00\u53d1\u73af\u5883\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u6784\u9020\u5305\u62ecWindows Forms\u5e94\u7528\u7a0b\u5e8f\u3001ASP.NET\u6216\u662fXML Web Service\u5728\u5185\u7684\u5404\u79cd.NET\u5e94\u7528\u3002<\/p>\n<p>\u8bf4\u4e86\u8fd9\u4e48\u591a\uff0c\u4f60\u8be5\u660e\u767d\u8be5\u600e\u4e48\u505a\u4e86\u5427\uff0c\u6253\u5f00\u60a8\u7684\u8ba1\u7b97\u673a\uff0c\u5b89\u88c5.NET Framework SDK\u548cVisual Studio.NET\uff0c\u7136\u540e\u5c31\u548c\u6211\u4e00\u8d77\u5f00\u59cb\u6211\u4eec\u7684.NET\u4e4b\u65c5\u5427\uff01<\/p>\n<p align=\"center\"><span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4bC#\u7a0b\u5e8f\u8bed\u8a00<\/span><\/p>\n<p>C#\u8bed\u8a00\u662f.NET\u5e73\u53f0\u4e2d\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u662f\u7531\u5fae\u8f6f\u516c\u53f8\u9886\u5bfc\u7814\u7a76\u5f00\u53d1\u7684\u65b0\u4e00\u4ee3\u9762\u5411\u7ec4\u4ef6\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u65e2\u4fdd\u6301\u4e86C++\u8bed\u8a00\u6240\u5177\u6709\u7684\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u53c8\u5728\u6b64\u57fa\u7840\u4e0a\u63d0\u4f9b\u4e86\u66f4\u591a\u7b80\u5355\u3001\u5b89\u5168\u7684\u7f16\u7a0b\u624b\u6bb5\u3002.NET\u5e73\u53f0\u81ea\u8eab\u7684\u5f88\u5927\u4e00\u90e8\u5206\u5c31\u662f\u7528\u8fd9\u79cd\u65b0\u578b\u7684C#\u8bed\u8a00\u6765\u5f00\u53d1\u7684\u3002<\/p>\n<p>\u4f9d\u7167\u60ef\u4f8b\uff0c\u6211\u4eec\u8fd8\u662f\u4ece\u201cHello World!\u201d\u5f00\u59cb\uff0c\u4f53\u9a8c\u4e00\u4e0bC#\u8bed\u8a00\u3002\u4e0b\u9762\u5c31\u662f\u4e00\u4e2a\u5178\u578b\u7684C# HelloWorld\u7a0b\u5e8f\uff1a<\/p>\n<p><strong><span style=\"color: #0000ff;\">using<\/span><\/strong> System;<br \/>\n<strong><span style=\"color: #0000ff;\">public<\/span><\/strong> <strong><span style=\"color: blue;\">class<\/span><\/strong> Hello<br \/>\n{<br \/>\n<strong><span style=\"color: #0000ff;\">public<\/span><\/strong> <strong><span style=\"color: blue;\">static<\/span><\/strong> <strong><span style=\"color: blue;\">void<\/span><\/strong> Main()<br \/>\n{<br \/>\nConsole.WriteLine(&#8220;Hello world!&#8221;);<br \/>\n}<br \/>\n}<\/p>\n<p>\u600e\u4e48\u6837\uff1f\u4e0d\u96be\u5427\u3002\u6709\u70b9\u50cfC\uff0c\u6709\u70b9\u50cfC++\uff0c\u6709\u70b9\u50cfVisual Basic\uff0c\u66f4\u50cfJAVA\u3002<\/p>\n<p>\u7a0b\u5e8f\u7684\u7b2c\u4e00\u884c\u6307\u5b9a\u4e86\u4e00\u4e2a\u5bf9\u4e8eSystem\u540d\u5b57\u7a7a\u95f4\uff08Namespace\uff09\u7684\u5f15\u7528\uff0c\u5f15\u7528\u4e86\u8fd9\u4e2a\u540d\u5b57\u7a7a\u95f4\uff0c\u6211\u4eec\u4e0b\u9762\u624d\u80fd\u65b9\u4fbf\u7684\u4f7f\u7528\u8fd9\u4e2a\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684\u7c7b\uff0c\u4f8b\u5982\u4e0b\u9762\u7684Console\u7c7b\u5c31\u662f\u5c5e\u4e8eSystem\u8fd9\u4e2a\u540d\u5b57\u7a7a\u95f4\u7684\u3002\u7b2c\u4e8c\u884c\u5f00\u59cb\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2aHello\u7c7b\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u9759\u6001\u7684Main\u65b9\u6cd5\uff08Method\uff09\uff0cC#\u4e2d\u6ca1\u6709\u4e86\u6210\u5458\u51fd\u6570\u7684\u6982\u5ff5\uff0c\u539f\u6765\u7684\u6210\u5458\u51fd\u6570\u73b0\u5728\u79f0\u4e3a\u662f\u201c\u65b9\u6cd5\u201d\uff0c\u800c\u539f\u6765\u7684\u6210\u5458\u53d8\u91cf\u88ab\u79f0\u4f5c\u201c\u5b57\u6bb5\uff08Field\uff09\u201d\u3002Main\u65b9\u6cd5\u662f\u4e00\u4e2aC#\u7a0b\u5e8f\u7684\u5f00\u59cb\u3002\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0cMain\u65b9\u6cd5\u552f\u4e00\u7684\u4e00\u884c\u53ef\u6267\u884c\u4ee3\u7801\u8c03\u7528\u4e86\u7cfb\u7edfConsole\u7c7b\u7684\u8f93\u51fa\u65b9\u6cd5\u663e\u793a\u5b57\u7b26\u4e32\u201cHello world!\u201d\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u628aC#\u4e0eC++\u8fdb\u884c\u4e00\u4e2a\u7b80\u5355\u7684\u5bf9\u6bd4\uff1a\u9996\u5148\uff0cC#\u662f\u5b8c\u5168\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\uff0c\u5b83\u4e0d\u518d\u6709\u5168\u5c40\u7684\u51fd\u6570\uff0c\u4efb\u4f55\u51fd\u6570\u90fd\u88ab\u5305\u542b\u5728\u67d0\u4e2a\u7c7b\u4e2d\u6210\u4e3a\u65b9\u6cd5\u3002C#\u4e2d\u4e0d\u518d\u9700\u8981\u51fd\u6570\u7684\u524d\u5411\u58f0\u660e\uff0c\u4f60\u6240\u9700\u8981\u7684\u51fd\u6570\u53ef\u4ee5\u5b9a\u4e49\u5728\u7c7b\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\u3002C#\u5728\u6700\u5927\u7a0b\u5ea6\u4e0a\u907f\u514d\u4e86\u6307\u9488\u7684\u4f7f\u7528\uff0c\u540c\u65f6\uff0c\u539f\u6765C++\u4e2d\u7684::\u3001-&gt;\u548c.\u64cd\u4f5c\u7b26\u88ab\u7edf\u4e00\u4e3a\u4e86.\u3002C#\u4e0d\u518d\u4f7f\u7528#include\u6765\u5305\u542b\u5176\u5b83\u7684\u7a0b\u5e8f\u6587\u672c\uff0c\u8fd9\u4f7f\u5f97.NET\u5e73\u53f0\u7684\u8bed\u8a00\u65e0\u5173\u6027\u5f97\u4ee5\u4f53\u73b0\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Viusal Basic.NET\u5199\u4e00\u4e2a\u7c7b\uff0c\u7136\u540e\u7528C#\u53bb\u8c03\u7528\u5b83\u751a\u81f3\u5728\u5b83\u57fa\u7840\u4e0a\u6d3e\u751f\u65b0\u7684\u7c7b\uff0c\u8fd9\u4f7f\u5f97\u8f6f\u4ef6\u590d\u7528\u8fbe\u5230\u4e86\u4e00\u4e2a\u65b0\u7684\u5883\u754c\u3002<\/p>\n<p>\u4e0b\u9762\u4f60\u5c31\u53ef\u4ee5\u8bd5\u4e00\u8bd5\u4e86\uff0c\u8fd9\u91cc\uff0c\u6211\u4eec\u6682\u65f6\u4e0d\u4f7f\u7528Visual Studio.NET\uff0c\u6211\u4eec\u7528\u547d\u4ee4\u884c\u7684\u65b9\u5f0f\u6765\u7f16\u8bd1\u8fd0\u884c\u8fd9\u4e2a\u7a0b\u5e8f\u3002<\/p>\n<p>\u6253\u5f00\u8bb0\u4e8b\u672c\uff0c\u8f93\u5165\u4e0a\u9762\u7684\u6e90\u4ee3\u7801\uff0c\u6ce8\u610f\u5927\u5c0f\u5199\uff0c\u7136\u540e\u5b58\u76d8\uff0c\u628a\u6587\u4ef6\u6269\u5c55\u540d\u6539\u6210.cs\uff08\u8fd9\u91cc\u6211\u4eec\u628a\u8fd9\u4e2a\u6587\u4ef6\u5b58\u4e3ahello.cs\uff09\uff0c\u8fd9\u662fC#\u6e90\u7a0b\u5e8f\u8981\u6c42\u7684\u6269\u5c55\u540d\u3002\u7136\u540e\u6253\u5f00\u4e00\u4e2aDOS\u7a97\u53e3\uff0c\u627e\u5230\u4f60\u5b58\u653e.cs\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u8f93\u5165<\/p>\n<p><span style=\"font-family: 'Courier New';\">csc hello.cs<\/span><\/p>\n<p>\u7cfb\u7edf\u5c31\u5f00\u59cb\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\uff0c\u5982\u679c\u6ca1\u6709\u51fa\u9519\u7684\u8bdd\uff0c\u4f1a\u751f\u6210hello.exe\u6587\u4ef6\uff0c\u8fd0\u884c\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u5c4f\u5e55\u4e0a\u7684\u8f93\u51fa\u4e86\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u4f7f\u7528Visual Studio.NET\u6765\u8fdb\u884cC#\u7a0b\u5e8f\u7684\u5f00\u53d1\u3002<\/p>\n<p>\u9996\u5148\u80af\u5b9a\u662f\u8981\u542f\u52a8Visual Studio.NET\u8f6f\u4ef6\u3002\u4e0b\u9762\u5c31\u662f\u5b83\u7684\u5f00\u53d1\u754c\u9762\uff0c\u5f88\u6f02\u4eae\u4e5f\u5f88\u53cb\u597d\u3002<\/p>\n<div id=\"attachment_929\" style=\"width: 458px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424b\" rel=\"attachment wp-att-929\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-929\" class=\"size-full wp-image-929\" title=\"Visual Studio .NET\u4e3b\u754c\u9762\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424B.jpg\" alt=\"Visual Studio .NET\u4e3b\u754c\u9762\" width=\"448\" height=\"328\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424B.jpg 448w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424B-300x219.jpg 300w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424B-409x300.jpg 409w\" sizes=\"auto, (max-width: 448px) 100vw, 448px\" \/><\/a><p id=\"caption-attachment-929\" class=\"wp-caption-text\">Visual Studio .NET\u4e3b\u754c\u9762<\/p><\/div>\n<p>\u6211\u4eec\u70b9\u51fb\u8d77\u59cb\u9875\u9762\u4e0a\u7684\u201cNew Project\u201d\u6309\u94ae\u65b0\u5efa\u9879\u76ee\uff0c\u5728\u5f39\u51fa\u7684\u201cNew Project\u201d\u5bf9\u8bdd\u6846\u4e2d\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u4e3a\u201cVisual C# Project\u201d\uff0c\u5e76\u9009\u53d6\u201cConsole Application\u201d\uff08\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\uff09\u6a21\u677f\uff0c\u8f93\u5165\u5408\u9002\u7684\u9879\u76ee\u540d\u79f0\uff08\u6211\u4eec\u8fd9\u91cc\u7528GuessNum1\uff09\u548c\u5b58\u653e\u4f4d\u7f6e\uff0c\u786e\u5b9a\u3002\u8fd9\u65f6\u7cfb\u7edf\u4f1a\u4e3a\u6211\u4eec\u751f\u6210\u4e00\u4e2a\u6700\u7b80\u5355\u7684C#\u5e94\u7528\u7a0b\u5e8f\u7684\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u5176\u57fa\u7840\u4e0a\u4fee\u6539\u6210\u6211\u4eec\u81ea\u5df1\u7684\u7a0b\u5e8f\u3002<\/p>\n<div id=\"attachment_930\" style=\"width: 329px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424c\" rel=\"attachment wp-att-930\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-930\" class=\"size-full wp-image-930\" title=\"\u65b0\u5efa\u9879\u76ee\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424C.jpg\" alt=\"\u65b0\u5efa\u9879\u76ee\" width=\"319\" height=\"207\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424C.jpg 319w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424C-300x194.jpg 300w\" sizes=\"auto, (max-width: 319px) 100vw, 319px\" \/><\/a><p id=\"caption-attachment-930\" class=\"wp-caption-text\">\u65b0\u5efa\u9879\u76ee<\/p><\/div>\n<p>\u6211\u4eec\u628a\u7cfb\u7edf\u751f\u6210\u7684\u7a0b\u5e8f\u6846\u67b6\u4fee\u6539\u6210\u4e0b\u9762\u7684\u6837\u5b50\uff1a<\/p>\n<p><strong><span style=\"color: #0000ff;\">using<\/span><\/strong> System; <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5f15\u7528\u7cfb\u7edf<\/span>System<span style=\"color: green; font-family: Fixedsys;\">\u540d\u5b57\u7a7a\u95f4<\/span><\/p>\n<p><strong><span style=\"color: #0000ff;\">namespace<\/span><\/strong> GuessNum1 <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5b9a\u4e49\u5c5e\u4e8e\u672c\u7a0b\u5e8f\u7684\u540d\u5b57\u7a7a\u95f4<br \/>\n<\/span>{<br \/>\n<span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: gray;\">&lt;summary&gt;<br \/>\n<\/span><span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: green;\"> Summary description for Class1.<br \/>\n<\/span><span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: gray;\">&lt;\/summary&gt;<br \/>\n<\/span><strong><span style=\"color: blue;\">class<\/span><\/strong> Class1 <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7cfb\u7edf\u81ea\u52a8\u751f\u6210\u7684<\/span>Class1<span style=\"color: green; font-family: Fixedsys;\">\u7c7b<br \/>\n<\/span>{<br \/>\n<span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: gray;\">&lt;summary&gt;<br \/>\n<\/span>   <span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: green;\"> The main entry point for the application.<br \/>\n<\/span>   <span style=\"color: gray;\">\/\/\/<\/span><span style=\"color: gray;\">&lt;\/summary&gt;<br \/>\n<\/span>   [STAThread]<br \/>\n<strong><span style=\"color: blue;\">static<\/span><\/strong> <strong><span style=\"color: blue;\">void<\/span><\/strong> Main(<strong><span style=\"color: blue;\">string<\/span><\/strong>[] args) <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u9759\u6001<\/span>Main<span style=\"color: green; font-family: Fixedsys;\">\u65b9\u6cd5<\/span><br \/>\n{<br \/>\n<span style=\"color: green;\">\/\/<br \/>\n<\/span>      <span style=\"color: green;\">\/\/ TODO: Add code to start application here<br \/>\n<\/span>      <span style=\"color: green;\">\/\/<br \/>\n<\/span>      GuessNum gn = <strong><span style=\"color: blue;\">new<\/span><\/strong> GuessNum(); <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7528<\/span>GuessNum <span style=\"color: green; font-family: Fixedsys;\">\u7c7b\u751f\u6210\u4e00\u4e2a\u5bf9\u8c61<br \/>\n<\/span>      gn.GenerateRandomNumber(); <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u4ea7\u751f\u968f\u673a\u6570\u4f5c\u4e3a\u88ab\u731c\u7684\u6570\u5b57<br \/>\n<\/span>      <strong><span style=\"color: blue;\">string<\/span><\/strong> answer; <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u7528\u4e8e\u4fdd\u5b58\u7528\u6237\u8f93\u5165\u7684\u731c\u6d4b\u503c<br \/>\n<\/span>      <strong><span style=\"color: blue;\">do<br \/>\n<\/span><\/strong>      {<br \/>\nanswer = Console.ReadLine();<br \/>\nConsole.WriteLine(gn.GetTip(answer));<br \/>\n} <strong><span style=\"color: blue;\">while<\/span><\/strong>(!gn.IsAnswerRight(answer)); <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u53cd\u590d\u8981\u6c42\u7528\u6237\u731c\u6570\u76f4\u5230\u731c\u6d4b\u6b63\u786e<br \/>\n<\/span>   }<br \/>\n}<br \/>\n<strong><span style=\"color: blue;\">class<\/span><\/strong> GuessNum <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u6211\u4eec\u81ea\u5df1\u5b9a\u4e49\u7684<\/span>GuessNum<span style=\"color: green; font-family: Fixedsys;\">\u7c7b\uff0c\u4ee5\u540e\u8fd8\u8981\u591a\u6b21\u7528\u5230<br \/>\n<\/span>{<br \/>\n<strong><span style=\"color: blue;\">private<\/span><\/strong> <strong><span style=\"color: blue;\">string<\/span><\/strong> correctAnswer; <span style=\"color: green;\">\/\/GuessNum<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7c7b\u7684\u79c1\u6709\u5b57\u6bb5\uff08\u6210\u5458\u53d8\u91cf\uff09\uff0c\u7528\u4e8e\u4fdd\u5b58\u6b63\u786e\u7b54\u6848<br \/>\n<\/span>   <strong><span style=\"color: blue;\">public<\/span><\/strong> GuessNum()<br \/>\n{<br \/>\ncorrectAnswer = &#8220;&#8221;;<br \/>\n}<br \/>\n<strong><span style=\"color: blue;\">public<\/span><\/strong> GuessNum(<strong><span style=\"color: blue;\">string<\/span><\/strong> answer)<br \/>\n{<br \/>\ncorrectAnswer = answer;<br \/>\n}<br \/>\n<strong><span style=\"color: blue;\">public<\/span><\/strong> <strong><span style=\"color: blue;\">string<\/span><\/strong> GenerateRandomNumber()<br \/>\n{<br \/>\n<strong><span style=\"color: blue;\">int<\/span><\/strong> [] a = <strong><span style=\"color: blue;\">new<\/span><\/strong> <strong><span style=\"color: blue;\">int<\/span><\/strong> [10]; <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5f00\u8f9f\u4e00\u4e2a\u5341\u4e2a\u5355\u5143\u7684\u6574\u5f62\u6570\u7ec4<br \/>\n<\/span>      <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u628a<\/span>0<span style=\"color: green; font-family: Fixedsys;\">\u5230<\/span>9<span style=\"color: green; font-family: Fixedsys;\">\u5341\u4e2a\u6570\u5b57\u4f9d\u6b21\u586b\u5165<\/span>a[0]<span style=\"color: green; font-family: Fixedsys;\">\u5230<\/span>a[9]<br \/>\n<strong><span style=\"color: blue;\">for<\/span><\/strong>(<strong><span style=\"color: blue;\">int<\/span><\/strong> i = 0; i &lt; 10; i++)<br \/>\na[i]=i;<br \/>\n<span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u628a\u8fd9\u4e2a\u5341\u6570\u5b57\u968f\u673a\u6253\u4e71<br \/>\n<\/span>      Random j = <strong><span style=\"color: blue;\">new<\/span><\/strong> Random();<br \/>\n<strong><span style=\"color: blue;\">for<\/span><\/strong>(<strong><span style=\"color: blue;\">int<\/span><\/strong> i = 0; i &lt; 10; i++)<br \/>\n{<br \/>\n<strong><span style=\"color: blue;\">int<\/span><\/strong> t = j.Next(10);<br \/>\n<strong><span style=\"color: blue;\">int<\/span><\/strong> s;<br \/>\ns = a[i];<br \/>\na[i] = a[t];<br \/>\na[t] = s;<br \/>\n}<br \/>\n<span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u53d6\u524d\u56db\u4e2a\u6570\u5b57\u7ec4\u6210\u56db\u4f4d\u6570\u505a\u4e3a\u731c\u6570\u5b57\u7684\u6b63\u786e\u7b54\u6848<br \/>\n<\/span>      correctAnswer = a[0].ToString() + a[1].ToString() + a[2].ToString() + a[3].ToString();<br \/>\n<strong><span style=\"color: blue;\">return<\/span><\/strong> correctAnswer;<br \/>\n}<br \/>\n<strong><span style=\"color: blue;\">public<\/span><\/strong> <strong><span style=\"color: blue;\">string<\/span><\/strong> GetTip(<strong><span style=\"color: blue;\">string<\/span><\/strong> answer) <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u672c\u65b9\u6cd5\u4e3a\u7528\u6237\u63d0\u4f9b\u731c\u6d4b\u63d0\u793a\uff0c\u76ee\u524d\u8fd8\u6ca1\u6709\u771f\u6b63\u5b8c\u5de5<br \/>\n<\/span>   {<br \/>\n<strong><span style=\"color: blue;\">if<\/span><\/strong> (IsAnswerRight(answer))<br \/>\n<strong><span style=\"color: blue;\">return<\/span><\/strong> &#8220;4A0B&#8221;;<br \/>\n<strong><span style=\"color: blue;\">else<br \/>\n<\/span><\/strong>        <strong><span style=\"color: blue;\">return<\/span><\/strong> &#8220;Wrong!&#8221;;<br \/>\n}<br \/>\n<strong><span style=\"color: blue;\">public<\/span><\/strong> <strong><span style=\"color: blue;\">bool<\/span><\/strong> IsAnswerRight(<strong><span style=\"color: blue;\">string<\/span><\/strong> answer) <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u672c\u65b9\u6cd5\u5224\u65ad\u7528\u6237\u7684\u731c\u6d4b\u662f\u5426\u6b63\u786e<br \/>\n<\/span>   {<br \/>\n<strong><span style=\"color: blue;\">if<\/span><\/strong> (answer == correctAnswer)<br \/>\n<strong><span style=\"color: blue;\">return<\/span><\/strong> <strong><span style=\"color: blue;\">true<\/span><\/strong>;<br \/>\n<strong><span style=\"color: blue;\">else<br \/>\n<\/span><\/strong>        <strong><span style=\"color: blue;\">return<\/span><\/strong> <strong><span style=\"color: blue;\">false<\/span><\/strong>;<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\u76f8\u4fe1\u5728\u4ee3\u7801\u8f93\u5165\u7684\u8fc7\u7a0b\u4e2d\u4f60\u4e00\u5b9a\u4f1a\u4f53\u9a8c\u5230Visual Studio.NET\u5f3a\u5927\u7684\u4ee3\u7801\u7f16\u8f91\u529f\u80fd\uff0c\u81ea\u52a8\u7f29\u8fdb\u5bf9\u9f50\u3001\u667a\u80fd\u611f\u5e94\u3001\u4ee3\u7801\u6298\u53e0\u5e94\u6709\u5c3d\u6709\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u7a0b\u5e8f\u672c\u8eab\u6ca1\u6709\u4ec0\u4e48\u592a\u591a\u7684\u53ef\u4ee5\u89e3\u91ca\u7684\u5730\u65b9\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u8fd9\u4e2a\u7a0b\u5e8f\u968f\u673a\u4ea7\u751f\u4e86\u4e00\u4e2a\u56db\u4f4d\u6570\u5b57\u5404\u4e0d\u76f8\u540c\u7684\u56db\u4f4d\u6570\uff0c\u7136\u540e\u7b49\u5f85\u7528\u6237\u8f93\u5165\uff0c\u5982\u679c\u8f93\u5165\u6b63\u786e\uff0c\u5c31\u663e\u793a\u201c4A0B\u201d\uff08\u8fd9\u4e2a\u4e0d\u7528\u6211\u518d\u8be6\u7ec6\u89e3\u91ca\u4e86\u5427\uff0c\u73a9\u8fc7\u731c\u6570\u5b57\u7684\u670b\u53cb\u90fd\u77e5\u9053\u8fd9\u4e2a\u63d0\u793a\u7684\u542b\u4e49\uff0cA\u524d\u9762\u7684\u6570\u5b57\u8868\u793a\u4f60\u731c\u5bf9\u4e86\u5e76\u653e\u5bf9\u4f4d\u7f6e\u7684\u6570\u5b57\u4e2a\u6570\uff0cB\u524d\u9762\u7684\u6570\u5b57\u8868\u793a\u4f60\u731c\u5bf9\u4e86\u6570\u5b57\u4f46\u653e\u9519\u4e86\u4f4d\u7f6e\u7684\u6570\u5b57\u7684\u4e2a\u6570\uff09\uff0c\u5982\u679c\u731c\u9519\u4e86\uff0c\u5c31\u663e\u793a\u201cWrong!\u201d\uff0c\u8ba9\u7528\u6237\u91cd\u65b0\u731c\u6d4b\u3002\u5f88\u660e\u663e\u8fd9\u4e2a\u6e38\u620f\u73b0\u5728\u8fd8\u4e0d\u597d\u73a9\uff0c\u731c\u9519\u4e86\u4ec5\u4ec5\u63d0\u793a\u201cWrong!\u201d\u662f\u8fdc\u8fdc\u4e0d\u591f\u7684\uff0c\u5e94\u8be5\u544a\u8bc9\u7528\u6237\u731c\u5bf9\u4e86\u51e0\u4e2a\u6570\u5b57\u548c\u653e\u9519\u4f4d\u4e86\u51e0\u4e2a\u6570\u5b57\u624d\u884c\u3002\u4e0d\u8981\u7740\u6025\uff0c\u6211\u4eec\u4f1a\u5728\u540e\u9762\u6162\u6162\u5b8c\u5584\u8fd9\u4e2a\u7a0b\u5e8f\u3002<\/p>\n<p>\u8fd9\u4e2a\u7a0b\u5e8f\u4e2d\u6709\u4e00\u4e2a\u503c\u5f97\u6ce8\u610f\u7684\u5730\u65b9\u662f\u5b83\u4f7f\u7528\u4e86\u201c\/\/\/\u201d\u5f62\u5f0f\u7684\u6ce8\u91ca\uff0c\u8fd9\u6837\u7684\u6ce8\u91ca\u53ef\u4ee5\u7528\u6765\u81ea\u52a8\u4ea7\u751f\u7a0b\u5e8f\u6587\u6863\uff0c\u5982\u679c\u5728\u91cc\u9762\u52a0\u4e0a\u4e00\u4e9b\u6807\u8bb0\u8fd8\u53ef\u4ee5\u4ea7\u751fXML\u5f62\u5f0f\u7684\u6587\u6863\u3002<\/p>\n<p>\u73b0\u5728\u4f60\u5c31\u53ef\u4ee5\u6309\u4e0bCtrl+F5\u952e\u8fd0\u884c\u7a0b\u5e8f\u4e86\uff0c\u8f93\u5165\u4e00\u4e2a4\u4f4d\u6570\uff0c\u5982\u679c\u6b63\u786e\uff0c\u7cfb\u7edf\u4e3a\u63d0\u793a\u201c4A0B\u201d\u5e76\u9000\u51fa\u7a0b\u5e8f\uff0c\u5982\u679c\u4e0d\u6b63\u786e\u5c31\u8f93\u51fa\u201cWrong\u201d\u3002\u7531\u4e8e\u6ca1\u6709\u8db3\u591f\u7684\u63d0\u793a\uff0c\u6050\u6015\u4f60\u662f\u4e0d\u592a\u53ef\u80fd\u731c\u5230\u6b63\u786e\u7684\u6570\u5b57\u7684\uff0c\u6240\u4ee5\u8fd8\u662f\u628a\u7a97\u53e3\u5173\u4e86\uff0c\u6211\u4eec\u7ee7\u7eed\u4e0b\u9762\u7684\u5185\u5bb9\u3002<\/p>\n<p align=\"center\"><span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4bWindows Forms\u7a0b\u5e8f\u8bbe\u8ba1<\/span><\/p>\n<p>\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u5728\u63a7\u5236\u53f0\u73af\u5883\u4e0b\u8fdb\u884c\u4e86\u4e00\u70b9C#\u7a0b\u5e8f\u7684\u5f00\u53d1\uff0c\u76ee\u7684\u53ea\u662f\u8ba9\u5927\u5bb6\u719f\u6089\u4e00\u4e0bC#\u8bed\u8a00\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u628a\u6211\u4eec\u5728\u63a7\u5236\u53f0\u4e0b\u5f00\u53d1\u7684\u7a0b\u5e8f\u79fb\u690d\u5230Windows\u7a97\u53e3\u754c\u9762\u4e2d\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u4eec\u9996\u5148\u5f15\u5165Windows Forms\u7684\u6982\u5ff5\uff1aWindows Forms\u662f\u5fae\u8f6f\u5728.NET\u5e73\u53f0\u4e0b\u63d0\u4f9b\u7684\u4e00\u79cd\u7a0b\u5e8f\u6784\u67b6\uff08Framework\uff09\uff0c\u5b83\u53ef\u4ee5\u652f\u6301\u591a\u79cd\u7a0b\u5e8f\u8bed\u8a00\uff0c\u4e3b\u8981\u7528\u4e8e\u5f00\u53d1\u5ba2\u6237\u7aef\u7684\u7a97\u53e3\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u7528Visual Studio.NET\u5e2e\u6211\u4eec\u751f\u6210\u4e00\u4e2a\u7b80\u5355\u7684Windows Forms\u6e90\u7a0b\u5e8f\uff0c\u6211\u4eec\u5c06\u5728\u5b83\u7684\u57fa\u7840\u4e0a\u5de5\u4f5c\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u6253\u5f00Visual Studio.NET\uff0c\u70b9\u51fb\u201cNew Project\u201d\uff0c\u9009\u62e9\u9879\u76ee\u7c7b\u578b\u4e3a\u201cVisual C# Project\u201d\uff0c\u7136\u540e\u9009\u62e9\u7a0b\u5e8f\u6a21\u677f\u4e3a\u201cWindows Application\u201d\uff0c\u8f93\u5165\u9879\u76ee\u540d\u79f0\u201cGuessNum2\u201d\uff0c\u786e\u5b9a\u3002<\/p>\n<p>\u6211\u4eec\u6309F5\u952e\u7f16\u8bd1\u8fd0\u884c\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u4e00\u4e2a\u7a7a\u767d\u7684\u7a97\u53e3\u5c31\u51fa\u73b0\u4e86\u3002\u6211\u4eec\u73b0\u5728\u8981\u505a\u7684\u5c31\u662f\u7ed9\u8fd9\u4e2a\u7a7a\u767d\u7a97\u53e3\u52a0\u4e0a\u6211\u4eec\u9700\u8981\u7684\u529f\u80fd\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8fdb\u884c\u53ef\u89c6\u5316\u7684\u754c\u9762\u90e8\u5206\u7684\u6784\u9020\uff0c\u4ece\u5de6\u8fb9\u7684Toolbox\u4e2d\u627e\u5230\u5408\u9002\u7684\u63a7\u4ef6\uff0c\u62d6\u66f3\u5230\u7a7a\u767d\u7a97\u53e3\u4e0a\uff0c\u4f7f\u5b83\u6210\u4e3a\u4e0b\u9762\u7684\u6837\u5b50\uff1a<\/p>\n<div id=\"attachment_931\" style=\"width: 243px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424d\" rel=\"attachment wp-att-931\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-931\" class=\"size-full wp-image-931\" title=\"\u7a97\u4f53\u8bbe\u8ba1\u5668\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424D.jpg\" alt=\"\u7a97\u4f53\u8bbe\u8ba1\u5668\" width=\"233\" height=\"218\" \/><\/a><p id=\"caption-attachment-931\" class=\"wp-caption-text\">\u7a97\u4f53\u8bbe\u8ba1\u5668<\/p><\/div>\n<p>\u8981\u8bf4\u660e\u7684\u4e00\u70b9\u662f\uff0c\u5728\u6784\u9020TextBox2\u65f6\uff0c\u8981\u6ce8\u610f\u628a\u5b83\u7684MultiLine\u5c5e\u6027\u548cReadOnly\u5c5e\u6027\u8bbe\u4e3aTrue\u3002\u5e76\u628aScrollBars\u5c5e\u6027\u8bbe\u4e3aVertical\u3002\u63a7\u4ef6\u5c5e\u6027\u503c\u7684\u4fee\u6539\u662f\u901a\u8fc7\u9009\u4e2d\u63a7\u4ef6\u540e\u7528Visual Studio.NET\u96c6\u6210\u73af\u5883\u53f3\u4e0b\u89d2\u7684\u201cProperties\u201d\u533a\u57df\u6765\u5b9e\u73b0\u7684\uff0c\u4fee\u6539\u8fc7\u7684\u5c5e\u6027\uff0c\u5176\u5c5e\u6027\u503c\u7684\u5b57\u4f53\u4f1a\u53d8\u7c97\u3002\u8fd9\u4e2aProperties\u533a\u57df\u8fd8\u6709\u4e00\u4e2a\u529f\u80fd\u5c31\u662f\u53ef\u4ee5\u4e3a\u63a7\u4ef6\u8fde\u63a5\u4e0d\u540c\u4e8b\u4ef6\u7684\u54cd\u5e94\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u70b9\u51fb\u4e0a\u9762\u7684Events\u6309\u94ae\u6765\u5207\u6362\u529f\u80fd\u3002<\/p>\n<div id=\"attachment_932\" style=\"width: 227px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424e\" rel=\"attachment wp-att-932\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-932\" class=\"size-full wp-image-932\" title=\"\u5c5e\u6027\u8bbe\u7f6e\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424E.jpg\" alt=\"\u5c5e\u6027\u8bbe\u7f6e\" width=\"217\" height=\"321\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424E.jpg 217w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424E-202x300.jpg 202w\" sizes=\"auto, (max-width: 217px) 100vw, 217px\" \/><\/a><p id=\"caption-attachment-932\" class=\"wp-caption-text\">\u5c5e\u6027\u8bbe\u7f6e<\/p><\/div>\n<p>\u53cc\u51fb\u7a97\u4f53\u7684\u7a7a\u767d\u90e8\u5206\uff0c\u7cfb\u7edf\u81ea\u52a8\u4e3a\u4f60\u751f\u6210\u4e86\u8fd9\u4e2a\u7a97\u4f53\u7684Load\u4e8b\u4ef6\u54cd\u5e94\u51fd\u6570Form1_Load()\uff0c\u6211\u4eec\u5148\u4e0d\u7740\u6025\u4fee\u6539\u5b83\uff0c\u5148\u628a\u5728\u4e0a\u4e00\u4e2a\u7a0b\u5e8f\u4e2d\u5199\u7684GuessNum\u7c7b\u7684\u4ee3\u7801\uff08\u4e0d\u5305\u62ecClass1\u7c7b\u7684\u4ee3\u7801\uff09\u8d34\u5728\u5f53\u524d\u4ee3\u7801\u7a97\u53e3\u4e2d\u7684\u4ee3\u7801\u7684\u6700\u540e\u4e00\u4e2a}\u524d\uff0c\u4f7f\u8fd9\u4e2a\u7c7b\u6210\u4e3a\u5f53\u524d\u7684GuessNum2\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684\u4e00\u4e2a\u7c7b\u3002<\/p>\n<p>\u7136\u540e\u5728Form1\u7c7b\u4e2d\u5199\u4e0a\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5373\u5728Form1\u7c7b\u4e2d\u5b9a\u4e49\u4e00\u4e2aGuessNum\u7c7b\u7684\u5bf9\u8c61gn\u3002\u7531\u4e8eC#\u4e0d\u8981\u6c42\u524d\u5411\u58f0\u660e\uff0c\u5e94\u6b64\u8fd9\u884c\u4ee3\u7801\u53ef\u4ee5\u5199\u5728Form1\u7c7b\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\uff0c\u5f53\u7136\u4e0d\u5305\u62ecForm1\u7c7b\u7684\u65b9\u6cd5\u4e2d\uff0c\u5982\u679c\u4f60\u628a\u8fd9\u884c\u4ee3\u7801\u5199\u5728Form1\u7c7b\u7684\u67d0\u4e2a\u65b9\u6cd5\u4e2d\uff0c\u8fd9\u5c31\u4e0d\u662f\u5728\u7c7b\u4e2d\u5b9a\u4e49\u5bf9\u8c61\u800c\u53d8\u6210\u662f\u5728\u67d0\u4e2a\u65b9\u6cd5\u4e2d\u5b9a\u4e49\u7684\u5c40\u90e8\u5bf9\u8c61\u4e86\u3002<\/p>\n<p><strong>private<\/strong> GuessNum gn;<\/p>\n<p>\u7136\u540e\u6211\u4eec\u518d\u4fee\u6539Form1_Load()\uff0c\u628a\u5b83\u4fee\u6539\u6210\u4e0b\u9762\u7684\u6837\u5b50\uff1a<\/p>\n<p><strong>private<\/strong> <strong><span style=\"color: blue;\">void<\/span><\/strong> Form1_Load(<strong><span style=\"color: blue;\">object<\/span><\/strong> sender, System.EventArgs e)<\/p>\n<p>{<\/p>\n<p>       textBox1.Text =  &#8220;&#8221;;<\/p>\n<p>       button1.Text = &#8220;Guess!&#8221;;<\/p>\n<p>       <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7528<\/span>GuessNum<span style=\"color: green; font-family: Fixedsys;\">\u7c7b\u751f\u6210\u4e00\u4e2a\u5bf9\u8c61\uff0c\u7136\u540e\u8ba9\u5b83\u4ea7\u751f\u88ab\u731c\u7684\u6570\u5b57\uff0c\u6700\u540e\u628a\u8fd9\u4e2a\u6570\u5b57\u663e\u793a\u5728<\/span>TextBox2<span style=\"color: green; font-family: Fixedsys;\">\u4e2d<\/span><\/p>\n<p>       <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u4e4b\u6240\u4ee5\u628a\u5b83\u663e\u793a\u5728<\/span>TextBox2<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u662f\u4e3a\u4e86\u4fbf\u4e8e\u4f60<\/span>\u201c<span style=\"color: green; font-family: Fixedsys;\">\u5077\u770b<\/span>\u201d<span style=\"color: green; font-family: Fixedsys;\">\u7b54\u6848\uff0c\u5426\u5219\u51ed\u7a7a\u731c\u662f\u51e0\u4e4e\u4e0d\u53ef\u80fd\u731c\u5230\u7b54\u6848\u7684<\/span><\/p>\n<p>       <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u6211\u4eec\u4f1a\u5728\u540e\u9762\u7684\u7a0b\u5e8f\u4e2d\u5b8c\u5584<\/span>GuessNum<span style=\"color: green; font-family: Fixedsys;\">\uff0c\u4f7f\u5b83\u7684<\/span>GetTip()<span style=\"color: green; font-family: Fixedsys;\">\u65b9\u6cd5\u53ef\u4ee5\u771f\u6b63\u8d77\u4f5c\u7528<\/span><\/p>\n<p>       gn = <strong><span style=\"color: blue;\">new<\/span><\/strong> GuessNum();<\/p>\n<p>       textBox2.Text = gn.GenerateRandomNumber();<\/p>\n<p>}<\/p>\n<p>\u70b9\u51fb\u4ee3\u7801\u7f16\u8f91\u5668\u4e0a\u90e8\u7684\u6807\u7b7e\uff0c\u5207\u6362\u56de\u7a97\u53e3\u8bbe\u8ba1\u5668\uff0c\u53cc\u51fbbutton1\u6309\u94ae\uff0c\u4e3a\u5b83\u6dfb\u52a0\u6309\u94ae\u54cd\u5e94\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n<p>     <strong><span style=\"color: blue;\">private<\/span><\/strong> <strong><span style=\"color: blue;\">void<\/span><\/strong> button1_Click(<strong><span style=\"color: blue;\">object<\/span><\/strong> sender, System.EventArgs e)<\/p>\n<p>     {<\/p>\n<p>       textBox2.Text = (textBox1.Text + &#8221;  &#8221; + gn.GetTip(textBox1.Text) + &#8220;\/r\/n&#8221; ) + textBox2.Text;<\/p>\n<p>       <strong><span style=\"color: blue;\">if<\/span><\/strong> (gn.IsAnswerRight(textBox1.Text))<\/p>\n<p>          textBox2.Text = &#8220;Congratulations! You get it!\/r\/n&#8221; + textBox2.Text;<\/p>\n<p>       textBox1.Text=&#8221;&#8221;;<\/p>\n<p>     }<\/p>\n<p>\u6211\u4eec\u518d\u6b21\u4f7f\u7528F5\u7f16\u8bd1\u8fd0\u884c\u8fd9\u4e2a\u7a0b\u5e8f\uff0c\u770b\uff0c\u5f88\u65b9\u4fbf\u7684\uff0c\u6211\u4eec\u5c31\u628a\u521a\u624d\u5728\u63a7\u5236\u53f0\u4e0b\u8fd0\u884c\u7684\u7a0b\u5e8f\u6539\u6210\u4e86Windows\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p align=\"center\"><span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4bASP.NET<\/span><\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u770b\u770b.NET\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206ASP.NET\u7684\u60c5\u51b5\u3002\u6211\u4eec\u5c06\u6f14\u793a\u7528ASP.NET\u8fc5\u901f\u5f00\u53d1\u4e00\u4e2a\u53ef\u4ee5\u5728Web\u4e0a\u73a9\u7684\u731c\u6570\u5b57\u6e38\u620f\u3002<\/p>\n<p>\u5728Visual Stuido.NET\u4e2d\uff0c\u6211\u4eec\u65b0\u5efa\u4e00\u4e2aASP.NET\u5e94\u7528\u7a0b\u5e8f\uff0c\u64cd\u4f5c\u65b9\u6cd5\u4e0e\u4e0a\u9762\u7684\u57fa\u672c\u76f8\u540c\uff0c\u53ea\u4e0d\u8fc7\u5728\u9009\u62e9\u9879\u76ee\u6a21\u677f\u65f6\u9009\u62e9\u4e3a\u201cASP.NET Web Application\u201d\uff0c\u8fd9\u6b21\uff0c\u6211\u4eec\u7528GuessNum3\u4f5c\u4e3a\u6211\u4eec\u7684\u9879\u76ee\u540d\u79f0\uff0c\u786e\u5b9a\u540e\u7cfb\u7edf\u4f1a\u81ea\u52a8\u4e0eIIS\u670d\u52a1\u5668\u8054\u7cfb\uff0c\u4e3a\u4f60\u5efa\u7acb\u597d\u865a\u62df\u76ee\u5f55\u548c\u4e00\u4e9b\u76f8\u5173\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u540c\u524d\u9762\u4e00\u6837\uff0c\u6211\u4eec\u6309F5\u8fd0\u884c\u8fd9\u4e2aASP.NET\u9879\u76ee\uff0c\u540c\u6837\u7684\u6211\u4eec\u4e5f\u662f\u5f97\u5230\u4e86\u4e00\u4e2a\u7a7a\u767d\u7684\u9875\u9762\u3002<\/p>\n<p>\u4e0b\u9762\u8981\u505a\u7684\u5de5\u4f5c\u4e0e\u524d\u9762\u7684\u7c7b\u4f3c\uff0c\u9996\u5148\u8981\u5728\u7a7a\u767d\u7684ASP.NET\u9875\u9762\u4e0a\u6dfb\u52a0\u670d\u52a1\u5668\u63a7\u4ef6\u3002\u4ec0\u4e48\u662f\u670d\u52a1\u5668\u63a7\u4ef6\uff1f\u7b80\u5355\u7684\u8bf4\uff0c\u670d\u52a1\u5668\u63a7\u4ef6\u5c31\u662f\u5728ASP.NET\u9875\u9762\u4e0a\u653e\u7f6e\u7684\u4e00\u79cd\u63a7\u4ef6\uff0c\u8fd9\u79cd\u63a7\u4ef6\u7684\u6b63\u5e38\u5de5\u4f5c\u662f\u5728\u670d\u52a1\u5668\u7aef\u5b8c\u6210\u7684\uff0c\u670d\u52a1\u5668\u5728\u5904\u7406\u5b8c\u63a7\u4ef6\u52a8\u4f5c\u540e\uff0c\u518d\u751f\u6210\u6807\u51c6\u7684HTML\u6587\u4ef6\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002\u6bd4\u5982\uff1a\u6211\u4eec\u5728\u9875\u9762\u4e0a\u653e\u7f6e\u4e00\u4e2aLabel\u63a7\u4ef6\uff0c\u5e76\u901a\u8fc7\u7a0b\u5e8f\u6539\u53d8\u5b83\u4e0a\u9762\u7684\u6587\u5b57\u4e3a\u201cHello World\u201d\uff0c\u670d\u52a1\u5668\u5728\u6536\u5230\u7528\u6237\u8bbf\u95ee\u8fd9\u4e2a\u9875\u9762\u7684\u8bf7\u6c42\u65f6\uff0c\u5b83\u5bf9Label\u63a7\u4ef6\u8fdb\u884c\u63a7\u5236\uff0c\u6539\u53d8\u5b83\u7684\u6807\u9898\u5c5e\u6027\uff0c\u6700\u7ec8\u751f\u6210HTML\u6587\u4ef6\u53d1\u9001\u7ed9\u7528\u6237\uff0c\u7528\u6237\u5bf9\u4e8e\u8fd9\u5e55\u540e\u7684\u4e00\u5207\u5e76\u4e0d\u77e5\u9053\uff0c\u4ed6\u6700\u7ec8\u6536\u5230\u7684\u6570\u636e\uff0c\u5c31\u662f\u4e00\u4e2a\u5305\u542b\u7740\u201cHello World\u201d\u5b57\u7b26\u4e32\u7684HTML\u9875\u9762\u3002<\/p>\n<p>\u5728\u9875\u9762\u4e0a\u6dfb\u52a0\u670d\u52a1\u5668\u63a7\u4ef6\u7684\u65b9\u6cd5\u4e0e\u524d\u9762\u5728\u7a97\u4f53\u4e0a\u6dfb\u52a0\u63a7\u4ef6\u7684\u65b9\u6cd5\u5b8c\u5168\u4e00\u81f4\uff0c\u53ea\u8981\u4eceToolbox\u4e2d\u70b9\u4e2d\u76f8\u5e94\u7684\u63a7\u4ef6\uff0c\u62d6\u653e\u5230\u9875\u9762\u4e0a\u5c31\u53ef\u4ee5\u4e86\u3002\u6211\u4eec\u6700\u7ec8\u5b8c\u6210\u540e\u7684\u9875\u9762\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div id=\"attachment_933\" style=\"width: 246px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424f\" rel=\"attachment wp-att-933\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-933\" class=\"size-full wp-image-933\" title=\"ASP.NET\u9875\u9762\u8bbe\u8ba1\u5668\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424F.jpg\" alt=\"ASP.NET\u9875\u9762\u8bbe\u8ba1\u5668\" width=\"236\" height=\"167\" \/><\/a><p id=\"caption-attachment-933\" class=\"wp-caption-text\">ASP.NET\u9875\u9762\u8bbe\u8ba1\u5668<\/p><\/div>\n<p>\u540c\u6837\u7684\uff0c\u4e0d\u8981\u5fd8\u4e86\u628atextBox2\u7684ReadOnly\u5c5e\u6027\u8bbe\u4e3aTrue\uff0c\u628aTextMode\u5c5e\u6027\u8bbe\u4e3aMultiLine\uff0c\u3002\u53e6\u5916\u4e3a\u4e86\u540e\u9762\u7684\u64cd\u4f5c\u53ef\u4ee5\u65b9\u4fbf\u4e00\u4e9b\uff0c\u8bf7\u628a\u8fd9\u4e09\u4e2a\u63a7\u4ef6\u7684(ID)\u5c5e\u6027\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u6539\u6210\u5c0f\u5199\uff0c\u5373\u628a\u8fd9\u4e09\u4e2a\u63a7\u4ef6\u7684ID\u7531\u539f\u6765\u7684TextBox1\u3001TextBox2\u3001Button1\u6539\u6210textBox1\u3001textBox2\u548cbutton1\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u8981\u505a\u7684\u5de5\u4f5c\u4e5f\u8bb8\u4f1a\u8ba9\u4f60\u89c9\u5f97\u6709\u70b9\u4f3c\u66fe\u76f8\u8bc6\uff1a<\/p>\n<p>\u53cc\u51fb\u9875\u9762\u7a7a\u767d\u5904\uff0c\u7cfb\u7edf\u4e3a\u4f60\u751f\u6210Page_Load()\u65b9\u6cd5\uff0c\u4e0d\u7ba1\u5b83\uff0c\u5728\u6e90\u7a0b\u5e8f\u7684\u6700\u540e\u4e00\u4e2a}\u524d\u52a0\u5165\u6211\u4eec\u4e0a\u4e00\u4e2a\u7a0b\u5e8f\u4e2d\u7684GuessNum\u7c7b\uff0c\u7136\u540e\u5728WebForm1\u7c7b\u4e2d\u52a0\u5165\u4e00\u884c\uff1a<\/p>\n<p>  <strong>private<\/strong> GuessNum gn;<\/p>\n<p>   \u7136\u540e\u4fee\u6539Page_Load()\u6210\u4e0b\u9762\u7684\u6837\u5b50\uff1a<\/p>\n<p>  <strong><span style=\"color: blue;\">private<\/span><\/strong> <strong><span style=\"color: blue;\">void<\/span><\/strong> Page_Load(<strong><span style=\"color: blue;\">object<\/span><\/strong> sender, System.EventArgs e)<\/p>\n<p>  {<\/p>\n<p>     <span style=\"color: green;\">\/\/ Put user code to initialize the page here<\/span><\/p>\n<p>     <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5224\u65ad\u662f\u7b2c\u4e00\u6b21\u8bbf\u95ee\u9875\u9762\u8fd8\u662f\u5237\u65b0\u8fc7\u9875\u9762<\/span><\/p>\n<p>     <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5982\u679c\u662f\u7b2c\u4e00\u6b21\u8bbf\u95ee\uff0c\u4ea7\u751f\u968f\u673a\u6570\u5e76\u5b58\u5728<\/span>Session<span style=\"color: green; font-family: Fixedsys;\">\u4e2d<\/span><\/p>\n<p>     <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5982\u679c\u4e0d\u662f\u7b2c\u4e00\u6b21\u8bbf\u95ee\uff0c\u4ece<\/span>Session<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u8bfb\u51fa\u524d\u9762\u4ea7\u751f\u7684\u503c\u7528\u4e8e\u6784\u9020<\/span>GuessNum<span style=\"color: green; font-family: Fixedsys;\">\u5bf9\u8c61<\/span><\/p>\n<p>     <strong><span style=\"color: blue;\">if<\/span><\/strong> (!Page.IsPostBack)<\/p>\n<p>     {<\/p>\n<p>       textBox1.Text =  &#8220;&#8221;;<\/p>\n<p>       button1.Text = &#8220;Guess!&#8221;;<\/p>\n<p>       gn = <strong><span style=\"color: blue;\">new<\/span><\/strong> GuessNum();<\/p>\n<p>       <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u4e0b\u9762\u7528\u5230\u4e86<\/span>ASP<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u719f\u6089\u7684\u5bf9\u8c61<\/span>Session<span style=\"color: green; font-family: Fixedsys;\">\uff0c\u4f46\u662f<\/span>ASP.NET<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u7684<\/span>Session<span style=\"color: green; font-family: Fixedsys;\">\u6bd4<\/span>ASP<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u7684\u66f4\u5f3a\u5927<\/span><\/p>\n<p>       Session[&#8220;answer&#8221;] = gn.GenerateRandomNumber();<\/p>\n<p>       <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u540c\u4e0a\u4e00\u4e2a<\/span>Windows Forms<span style=\"color: green; font-family: Fixedsys;\">\u7a0b\u5e8f\u4e00\u6837\uff0c\u6211\u4eec\u628a\u6807\u51c6\u7b54\u6848\u5148\u663e\u793a\u5728<\/span>textBox2<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\uff0c\u4fbf\u4e8e\u4f60\u6d4b\u8bd5\u7a0b\u5e8f<\/span><\/p>\n<p>       textBox2.Text = Session[&#8220;answer&#8221;].ToString();<\/p>\n<p>     }<\/p>\n<p>     <strong><span style=\"color: blue;\">else<\/span><\/strong><\/p>\n<p>       gn = <strong><span style=\"color: blue;\">new<\/span><\/strong> GuessNum(Session[&#8220;answer&#8221;].ToString());<\/p>\n<p>  }<\/p>\n<p>\u8fd4\u56deWeb\u8868\u5355\u8bbe\u8ba1\u5668\uff0c\u53cc\u51fbButton\u6309\u94ae\uff0c\u5728\u51fa\u73b0\u7684button1_Click()\u4e2d\u52a0\u5165\u4e0e\u4e0a\u4e00\u4e2aWindows Forms\u7a0b\u5e8f\u4e2d\u76f8\u540c\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u597d\u4e86\uff0c\u8fd0\u884c\u4e00\u4e0b\u8bd5\u8bd5\u3002\u4e0d\u51fa\u6240\u6599\uff0c\u4e00\u4e2a\u53ef\u4ee5\u5728Web\u4e0a\u8fd0\u884c\u7684\u731c\u6570\u5b57\u6e38\u620f\u5df2\u7ecf\u521d\u5177\u96cf\u5f62\u4e86\u3002<\/p>\n<p>\u7ecf\u8fc7\u4e0a\u9762\u7684\u6f14\u793a\uff0c\u4f60\u662f\u4e0d\u662f\u5bf9ASP.NET\u6709\u4e86\u4e00\u4e2a\u521d\u6b65\u7684\u8ba4\u8bc6\u5462\uff1f\u5728ASP.NET\u4e2d\uff0c\u4e0d\u7528\u518d\u50cf\u4ece\u524d\u5728ASP\u4e2d\u90a3\u6837\u628a\u811a\u672c\u63d2\u5728HTML\u6587\u4ef6\u4e2d\uff0c\u8fdb\u884c\u4e86\u754c\u9762\u8bbe\u8ba1\u4e0e\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u5206\u79bb\uff08\u628a\u9875\u9762\u8bbe\u8ba1\u7684\u90e8\u5206\u653e\u5728\u4e00\u4e2a.aspx\u6587\u4ef6\u4e2d\uff0c\u628a\u4ee3\u7801\u90e8\u5206\u653e\u5728\u4e00\u4e2a.cs\u6216.vb\u7684\u4ee3\u7801\u6587\u4ef6\u4e2d\uff0c\u8be5\u6280\u672f\u88ab\u79f0\u4e3aCode Behind\uff09\uff0c\u5e76\u4e14\u4f7fASP.NET\u9875\u9762\u4e5f\u5448\u73b0\u51fa\u4e00\u79cd\u4e8b\u4ef6\u9a71\u52a8\u7684\u7279\u6027\u3002\u8fd9\u5c31\u4f7f\u5f97\u4ee3\u7801\u7684\u91cd\u7528\u6027\u5f97\u5230\u5927\u5927\u7684\u52a0\u5f3a\uff0c\u5c31\u50cf\u4f60\u770b\u5230\u7684\u90a3\u6837\uff0c\u6211\u4eec\u5728ASP.NET\u4e2d\u4f7f\u7528\u7684\u4ee3\u7801\u4e0e\u5728Windows Forms\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\u4f7f\u7528\u7684\u4ee3\u7801\u662f\u76f8\u5f53\u4e00\u81f4\u7684\u3002<\/p>\n<p>\u53e6\u4e00\u65b9\u9762\uff0cASP.NET\u7684\u4ee3\u7801\u5206\u79bb\u6280\u672f\u4e0d\u4f46\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387\uff0c\u4e5f\u63d0\u9ad8\u4e86\u8fd0\u884c\u6548\u7387\uff0cASP.NET\u4e0d\u518d\u662f\u89e3\u91ca\u6267\u884c\u7684\uff0c\u5b83\u662f\u5728\u7528\u6237\u7b2c\u4e00\u6b21\u8bbf\u95ee\u4e00\u4e2a\u65b0\u7684\u9875\u9762\u65f6\uff0c\u5bf9\u90a3\u4e2a\u9875\u9762\u7684\u4ee3\u7801\u8fdb\u884c\u7f16\u8bd1\uff0c\u4ee5\u540e\u7684\u7528\u6237\u8bbf\u95ee\u5c31\u6267\u884c\u7684\u662f\u7f16\u8bd1\u540e\u7684\u4ee3\u7801\uff0c\u8fd0\u884c\u6548\u7387\u81ea\u7136\u6709\u4e86\u5de8\u5927\u7684\u63d0\u9ad8\u3002\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u611f\u89c9\u7684ASP.NET\u7f51\u9875\u7b2c\u4e00\u6b21\u8bbf\u95ee\u65f6\u901f\u5ea6\u7279\u522b\u6162\u7684\u539f\u56e0\u3002<\/p>\n<p>\u4ece\u7528\u6237\u7684\u89d2\u5ea6\u6765\u770b\uff0cASP.NET\u4e5f\u66f4\u5bb9\u6613\u4f7f\u7528\u4e86\uff0c\u8bbf\u95ee\u4e00\u4e2aASP.NET\u9875\u9762\u5c31\u50cf\u662f\u4f7f\u7528\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u4e00\u6837\u3002\u4e8b\u5b9e\u4e0a\uff0c\u6211\u4eec\u4e0a\u9762\u7f16\u5199\u7684Windows Forms\u7684\u5e94\u7528\u7a0b\u5e8f\u4e5f\u4e0d\u540c\u4e8e\u4e00\u822c\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982\u679c\u628a\u5b83\u653e\u5728Web\u4e0a\uff0c\u5f53\u7528\u6237\u70b9\u51fb\u6307\u5411\u5b83\u7684\u94fe\u63a5\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u76f4\u63a5\u81ea\u52a8\u4e0b\u8f7d\u5e76\u8fd0\u884c\u5b83\uff08\u5f53\u7136\uff0c\u5fae\u8f6f\u516c\u53f8\u505a\u4e86\u5f88\u591a\u5de5\u4f5c\u6765\u4fdd\u8bc1\u5176\u5b89\u5168\u6027\uff09\u3002\u5728.NET\u65f6\u4ee3\uff0c\u7f51\u7edc\u4e0e\u684c\u9762\u5e94\u7528\u7a0b\u5e8f\u7684\u754c\u7ebf\u5df2\u7ecf\u8d8a\u6765\u8d8a\u4e0d\u660e\u663e\u3002<\/p>\n<p align=\"center\"><span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4bWeb Service<\/span><\/p>\n<p>Web Service\u662f\u5fae\u8f6f\u5728.NET\u4e2d\u5f15\u5165\u7684\u4e00\u4e2a\u8f83\u65b0\u7684\u6982\u5ff5\u3002\u5728\u4f20\u7edf\u7684\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u53d1\u4eba\u5458\u4e00\u76f4\u901a\u8fc7\u96c6\u6210\u672c\u5730\u7cfb\u7edf\u670d\u52a1\u6765\u6784\u5efa\u5e94\u7528\u7a0b\u5e8f\u3002\u73b0\u5728Web Service\u7684\u51fa\u73b0\uff0c\u53ef\u4ee5\u8ba9\u5f00\u53d1\u4eba\u5458\u8f7b\u677e\u7684\u6784\u5efa\u5177\u6709\u590d\u6742\u7ed3\u6784\u7684N\u5c42\u7cfb\u7edf\u3002Web Serivce\u662f\u8fd9\u6837\u7684\u4e00\u79cd\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u4f7f\u7528\u6807\u51c6\u7684HTTP\u534f\u8bae\u548cXML\uff0c\u5c06\u8f6f\u4ef6\u7684\u529f\u80fd\u4f53\u73b0\u5728\u7f51\u7edc\u4e0a\u3002\u660e\u786e\u4e00\u70b9\u8bf4\uff0c\u5c31\u662f\u5728Web\u670d\u52a1\u5668\u4e0a\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\uff0c\u5b83\u53ef\u4ee5\u54cd\u5e94\u8fdc\u7a0b\u7a0b\u5e8f\u7684\u8bf7\u6c42\u3001\u63a5\u53d7\u8fd0\u7a0b\u7a0b\u5e8f\u53d1\u6765\u7684\u6570\u636e\uff0c\u5904\u7406\u540e\u518d\u5c06\u6570\u636e\u8fd4\u56de\u3002<\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u60f3\u901a\u8fc7Web Service\u4e3a\u6211\u4eec\u7684\u731c\u6570\u5b57\u6e38\u620f\u63d0\u4f9b\u4e00\u4e2a\u4ea7\u751f\u63d0\u793a\u4fe1\u606f\u7684\u7684\u670d\u52a1\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u5c06\u731c\u6570\u5b57\u7684\u6807\u51c6\u7b54\u6848\u4e0e\u7528\u6237\u6240\u731c\u7684\u6570\u5b57\u63d0\u4f9b\u7ed9\u670d\u52a1\u5668\u4e0a\u7684Web Service\uff0c\u670d\u52a1\u5668\u5224\u65ad\u7528\u6237\u731c\u6d4b\u7684\u6b63\u786e\u6027\uff0c\u5e76\u8fd4\u56de\u731c\u5bf9\u5e76\u653e\u5bf9\u4f4d\u7f6e\u7684\u6570\u5b57\u4e2a\u6570\u548c\u731c\u5bf9\u4f46\u672a\u653e\u5bf9\u4f4d\u7f6e\u7684\u6570\u5b57\u4e2a\u6570\u3002\u6709\u4e9b\u670b\u53cb\u4e00\u5b9a\u4f1a\u95ee\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u660e\u660e\u53ef\u4ee5\u5728\u672c\u5730\u5b8c\u6210\uff0c\u4e3a\u4ec0\u4e48\u8981\u8f6c\u4e2a\u5927\u5708\u5b50\uff0c\u5728\u670d\u52a1\u5668\u4e0a\u7528Web Service\u5b8c\u6210\u5462\uff1f\u8fd9\u4e2a\u64cd\u4f5c\u786e\u5b9e\u53ef\u4ee5\u76f4\u63a5\u5728\u4e0a\u9762\u7684C#\u7a0b\u5e8f\u4e2d\u6dfb\u52a0\u4ee3\u7801\u5b8c\u6210\uff0c\u6211\u4eec\u4e0d\u8fd9\u6837\u505a\u7684\u539f\u56e0\u5c31\u662f\u4e3a\u4e86\u4e3a\u5927\u5bb6\u6f14\u793aWeb Service\u7684\u7528\u9014\u3002\u4f60\u53ef\u4ee5\u8bbe\u60f3\u7a0b\u5e8f\u8981\u8bbf\u95ee\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u7684\u4e00\u4e2a\u6570\u636e\u5e93\uff0c\u6839\u636e\u7528\u6237\u63d0\u4ea4\u7684\u4e0d\u540c\u4fe1\u606f\uff0c\u8fd4\u56de\u4e0d\u540c\u7684\u6570\u636e\uff0c\u8fd9\u65f6Web Service\u5c31\u5927\u6709\u7528\u6b66\u4e4b\u5730\u4e86\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8fd8\u662f\u4f7f\u7528Visual Studio.NET\u4e3a\u6211\u4eec\u751f\u6210\u4e00\u4e2a\u7a7a\u7684Web Service\u9879\u76ee\u3002\u4e0e\u524d\u9762\u4e0d\u540c\u7684\u662f\uff0c\u8fd9\u4e00\u6b21\uff0c\u6211\u4eec\u91c7\u7528.NET\u4e2d\u53e6\u4e00\u79cd\u91cd\u8981\u7684\u8bed\u8a00\u2014\u2014Visual Basic.NET\u2014\u2014\u6765\u5f00\u53d1\u6211\u4eec\u7684Web Service\uff0c\u8fd9\u6ca1\u6709\u4ec0\u4e48\u7279\u6b8a\u7684\u610f\u601d\uff0c\u53ea\u4e0d\u8fc7\u60f3\u4e0e\u5927\u5bb6\u4e00\u8d77\u4f53\u9a8c\u4e00\u4e0b\u5168\u65b0\u7684Visual Basic.NET\u8bed\u8a00\u3002<\/p>\n<p>\u6253\u5f00Visual Studio.NET\uff0c\u70b9\u201cNew Project\u201d\uff0c\u5728Project Type\u4e2d\u9009\u62e9Visual Basic Project\uff0c\u5728Template\u4e2d\u9009\u62e9ASP.NET Web Service\uff0c\u5728\u4e0b\u9762\u8f93\u5165\u5de5\u7a0b\u540d\u5b57GuessNumService\uff0c\u786e\u5b9a\u3002<\/p>\n<p>\u5de5\u7a0b\u6784\u9020\u597d\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u8bbe\u8ba1\u9875\u9762\uff0c\u4e0a\u9762\u6709\u4e24\u884c\u5b57\uff0c\u70b9\u201cclick here to switch to code view\u201d\u76f4\u63a5\u5207\u6362\u5230\u4ee3\u7801\u7f16\u8f91\u89c6\u56fe\uff0c\u5f00\u59cb\u6211\u4eec\u7684\u4ee3\u7801\u7f16\u5199\u3002\u8bbe\u8ba1\u9875\u9762\u4e3b\u8981\u662f\u7528\u4e8e\u6dfb\u52a0\u4e00\u4e9b\u7ec4\u4ef6\u6216\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n<p>\u5728\u4ee3\u7801\u89c6\u56fe\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4e00\u4e2a\u88ab\u6ce8\u91ca\u6389\u7684HelloWorld\u51fd\u6570\uff0c\u8fd9\u5176\u5b9e\u662f\u4e00\u4e2a\u8303\u4f8b\uff0c\u544a\u8bc9\u5927\u5bb6\u5efa\u7acbWeb Service\u7684\u65b9\u6cd5\uff0c\u6309\u7167\u5b83\u7684\u6837\u5b50\uff0c\u6211\u4eec\u8f93\u5165\u4e0b\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n<p>&#8216; &lt;WebMethod()&gt; <span style=\"color: green; font-family: Fixedsys;\">\u662f\u7ed9\u51fd\u6570\u6307\u5b9a\u7684\u4e00\u4e2a\u5c5e\u6027<\/span>(Attribute)<span style=\"color: green; font-family: Fixedsys;\">\uff0c\u6307\u660e\u8fd9\u4e2a\u51fd\u6570\u5c06\u505a\u4e3a\u4e00\u4e2a<\/span>Web Service<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u7684\u51fd\u6570\u5411\u5916\u53d1\u5e03<\/span><\/p>\n<p>    &lt;WebMethod()&gt; <strong><span style=\"color: blue;\">Public<\/span><\/strong> <strong><span style=\"color: blue;\">Function<\/span><\/strong> GetTip(<strong><span style=\"color: blue;\">ByVal<\/span><\/strong> correctAnswer <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">String<\/span><\/strong>, <strong><span style=\"color: blue;\">ByVal<\/span><\/strong> userAnswer <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">String<\/span><\/strong>) <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">String<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">Dim<\/span><\/strong> i <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">Integer<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">Dim<\/span><\/strong> j <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">Integer<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">Dim<\/span><\/strong> a <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">Integer<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">Dim<\/span><\/strong> b <strong><span style=\"color: blue;\">As<\/span><\/strong> <strong><span style=\"color: blue;\">Integer<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">For<\/span><\/strong> i = 1 <strong><span style=\"color: blue;\">To<\/span><\/strong> 4<\/p>\n<p>            <strong><span style=\"color: blue;\">For<\/span><\/strong> j = 1 <strong><span style=\"color: blue;\">To<\/span><\/strong> 4<\/p>\n<p>                <strong><span style=\"color: blue;\">If<\/span><\/strong> Mid(correctAnswer, j, 1) = Mid(userAnswer, i, 1) <strong><span style=\"color: blue;\">Then<\/span><\/strong><\/p>\n<p>                    <strong><span style=\"color: blue;\">If<\/span><\/strong> j = i <strong><span style=\"color: blue;\">Then<\/span><\/strong><\/p>\n<p>                        a += 1 <span style=\"color: green;\">&#8216;VB<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7a0b\u5e8f\u5458\u5e38\u5e38\u7fa1\u6155<\/span>C++<span style=\"color: green; font-family: Fixedsys;\">\u7a0b\u5e8f\u5458\u8fd9\u79cd\u7b80\u6d01\u7684\u5199\u6cd5\uff0c\u73b0\u5728<\/span>VB<span style=\"color: green; font-family: Fixedsys;\">\u7684\u7a0b\u5e8f\u5458\u4e5f\u53ef\u4ee5\u7528\u4e86\uff01<\/span><\/p>\n<p>                    <strong><span style=\"color: blue;\">Else<\/span><\/strong><\/p>\n<p>                        b += 1<\/p>\n<p>                    <strong><span style=\"color: blue;\">End<\/span><\/strong> <strong><span style=\"color: blue;\">If<\/span><\/strong><\/p>\n<p>                <strong><span style=\"color: blue;\">End<\/span><\/strong> <strong><span style=\"color: blue;\">If<\/span><\/strong><\/p>\n<p>            <strong><span style=\"color: blue;\">Next<\/span><\/strong><\/p>\n<p>        <strong><span style=\"color: blue;\">Next<\/span><\/strong><\/p>\n<p>        <span style=\"color: green;\">&#8216;<\/span><span style=\"color: green; font-family: Fixedsys;\">\u4e0b\u9762\u7528\u5230\u7684<\/span>ToString()<span style=\"color: green; font-family: Fixedsys;\">\u65b9\u6cd5\u51e0\u4e4e\u662f\u4efb\u4f55\u4e00\u79cd\u7c7b\u578b\u7684\u6570\u636e\u90fd\u652f\u6301\u7684\u7c7b\u578b\u8f6c\u6362\u51fd\u6570<\/span><\/p>\n<p>        <span style=\"color: green;\">&#8216;<\/span><span style=\"color: green; font-family: Fixedsys;\">\u5728<\/span>VB<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u5982\u4f55\u628a\u6574\u578b\u7684<\/span>4<span style=\"color: green; font-family: Fixedsys;\">\u8f6c\u6210\u5b57\u7b26\u4e32\u578b\uff1f<\/span>STR(4)<span style=\"color: green; font-family: Fixedsys;\">\u5427\u3002\u5728<\/span>VB.NET<span style=\"color: green; font-family: Fixedsys;\">\u4e2d\u4f60\u53ef\u5199\u6210<\/span>4.ToString()<span style=\"color: green; font-family: Fixedsys;\">\uff01<\/span><\/p>\n<p>        GetTip = a.ToString() + &#8220;A&#8221; + b.ToString() + &#8220;B&#8221;<\/p>\n<p>    <strong><span style=\"color: blue;\">End<\/span><\/strong> <strong><span style=\"color: blue;\">Function<\/span><\/strong><\/p>\n<p>\u4e0b\u9762\u6211\u4eec\u5c31\u53ef\u4ee5\u6765\u6d4b\u8bd5\u4e00\u4e0b\u8fd9\u4e2aWeb Service\u4e86\uff0c\u6309F5\u952e\uff0cVisual Studio.NET\u81ea\u52a8\u6253\u5f00IE\u6765\u6d4b\u8bd5\u8fd9\u4e2aWeb Service\uff0c\u6211\u4eec\u770b\u5230\u4e0b\u9762\u7684\u753b\u9762\uff1a<\/p>\n<div id=\"attachment_934\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424g\" rel=\"attachment wp-att-934\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-934\" class=\"size-full wp-image-934\" title=\"Web Service\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424G.jpg\" alt=\"Web Service\" width=\"340\" height=\"277\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424G.jpg 340w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424G-300x244.jpg 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/a><p id=\"caption-attachment-934\" class=\"wp-caption-text\">Web Service<\/p><\/div>\n<p>\u8fd9\u5c31\u662f.NET\u4e3a\u6211\u4eec\u81ea\u52a8\u751f\u6210\u7684\u670d\u52a1\u6d4b\u8bd5\u9875\u9762\uff0c\u8fd9\u4e2a\u9875\u9762\u4e0a\u5217\u51fa\u4e86\u5f53\u524d\u7684Service1\u670d\u52a1\u4e2d\u63d0\u4f9b\u7684\u6240\u6709\u51fd\u6570\uff0c\u73b0\u5728\u53ea\u6709\u4e00\u4e2aGetTip()\u3002\u540c\u65f6\u8fd9\u4e2a\u9875\u9762\u4e0a\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2aService Description\u7684\u94fe\u63a5\uff0c\u70b9\u51fb\u5b83\uff0c\u53ef\u4ee5\u770b\u5230\u4ee5XML\u63cf\u8ff0\u7684\u670d\u52a1\u8bf4\u660e\uff0c\u6211\u4eec\u79f0\u4e4b\u4e3aWSDL\uff0c\u5373Web Service Description Language\u3002<\/p>\n<p>\u8fd9\u91cc\uff0c\u6211\u63d0\u9192\u5927\u5bb6\u628a\u6d4f\u89c8\u5668\u5730\u5740\u680f\u4e2d\u7684\u5730\u5740Copy\u4e0b\u6765\uff0c\u4e00\u4f1a\u513f\u6211\u4eec\u4f1a\u7528\u5230\u5b83\uff0c\u5728\u6211\u7684\u673a\u5668\u4e0a\u8fd9\u4e2a\u5730\u5740\u662fhttp:\/\/localhost\/GuessNumService\/Service1.asmx\uff0c\u4ece\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0cWeb Service\u7684\u6587\u4ef6\u6269\u5c55\u540d\u662fasmx\u3002<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u70b9\u51fb\u201cGetTip\u201d\u6765\u6d4b\u8bd5\u8fd9\u4e2aWeb\u670d\u52a1\uff0c\u5206\u522b\u5728correctAnswer\u548cuserAnswer\u4e24\u4e2a\u6587\u672c\u6846\u4e2d\u8f93\u5165\u6570\u5b57\uff0c\u7136\u540e\u70b9\u51fbInvoke\uff0c\u7ed3\u679c\u5c31\u4f1a\u4ee5XML\u7684\u5f62\u5f0f\u8fd4\u56de\u3002<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u5206\u522b\u8f93\u51653684\u548c4628\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u7528\u6237\u662f\u731c\u5bf9\u4e86\u4e00\u4e2a\u6570\u5b57\u201c6\u201d\uff0c\u8fd8\u731c\u5230\u4e86\u4e24\u4e2a\u6570\u5b57\u201c4\u201d\u548c\u201c8\u201d\uff0c\u4f46\u653e\u9519\u4e86\u4f4d\u7f6e\uff0c\u6240\u4ee5\u8fd4\u56de\u7684\u63d0\u793a\u5e94\u8be5\u662f1A2B\uff0c\u6d4b\u8bd5\u4e00\u4e0b\uff0c\u679c\u7136\u5982\u6b64\uff01<\/p>\n<div id=\"attachment_935\" style=\"width: 350px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424h\" rel=\"attachment wp-att-935\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-935\" class=\"size-full wp-image-935\" title=\"\u6d4b\u8bd5Web Service\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424H.jpg\" alt=\"\u6d4b\u8bd5Web Service\" width=\"340\" height=\"277\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424H.jpg 340w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424H-300x244.jpg 300w\" sizes=\"auto, (max-width: 340px) 100vw, 340px\" \/><\/a><p id=\"caption-attachment-935\" class=\"wp-caption-text\">\u6d4b\u8bd5Web Service<\/p><\/div>\n<div id=\"attachment_936\" style=\"width: 432px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424i\" rel=\"attachment wp-att-936\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-936\" class=\"size-full wp-image-936\" title=\"Web Service XML\u8fd4\u56de\u7ed3\u679c\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424I.jpg\" alt=\"Web Service XML\u8fd4\u56de\u7ed3\u679c\" width=\"422\" height=\"232\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424I.jpg 422w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424I-300x164.jpg 300w\" sizes=\"auto, (max-width: 422px) 100vw, 422px\" \/><\/a><p id=\"caption-attachment-936\" class=\"wp-caption-text\">Web Service XML\u8fd4\u56de\u7ed3\u679c<\/p><\/div>\n<p>Web Service \u8bd5\u9a8c\u6210\u529f\uff01\u6211\u4eec\u7ec8\u4e8e\u53ef\u4ee5\u5f00\u59cb\u6784\u9020\u4e00\u4e2a\u5b8c\u6574\u7684\u731c\u6570\u5b57\u6e38\u620f\u4e86\uff01<\/p>\n<p>\u65b0\u5efa\u4e00\u4e2aVisual C#\u7684Windows Application\uff08\u4f60\u4e5f\u53ef\u4ee5\u76f4\u63a5\u6253\u5f00\u524d\u9762\u505a\u597d\u7684GuessNum2\uff0c\u6211\u4eec\u5148\u5728\u8981\u505a\u7684\u53ea\u662f\u5728\u5b83\u57fa\u7840\u4e0a\u7684\u4fee\u6539\uff09\uff0c\u547d\u540d\u4e3aGuessNumFinal\uff0c\u4e0e\u524d\u9762\u505aGuessNum2\u65f6\u4e00\u6837\u8bbe\u8ba1\u6e38\u620f\u7a97\u4f53\uff0c\u5e76\u4ee5\u540c\u6837\u7684\u65b9\u6cd5\uff0c\u628aGuessNum\u7c7b\u52a0\u5165GuessNumFinal\u540d\u5b57\u7a7a\u95f4\uff0c\u5728Form1\u7c7b\u4e2d\u6dfb\u52a0\u4e00\u4e2aGuessNum\u7684\u79c1\u6709\u6210\u5458\uff0c\u7136\u540e\u6dfb\u52a0\u7a97\u4f53\u7684Form1_Load\u548c\u6309\u94ae\u7684button1_Click\u65b9\u6cd5\u3002<\/p>\n<p>\u4e0b\u9762\u8981\u505a\u7684\uff0c\u5c31\u662f\u8981\u4fee\u6539GuessNum\u7c7b\u7684GetTip\u65b9\u6cd5\uff0c\u4f7f\u5b83\u4e0d\u518d\u7b80\u5355\u7684\u8fd4\u56de\u4e00\u4e2a\u201cWrong!\u201d\u800c\u662f\u901a\u8fc7\u8c03\u7528Web Service\uff0c\u628a\u6807\u51c6\u7b54\u6848\u548c\u7528\u6237\u8f93\u5165\u63d0\u4f9b\u7ed9\u5b83\uff0c\u8ba9\u5b83\u8fd4\u56de\u4e00\u4e2a\u201cxAyB\u201d\u5f62\u5f0f\u7684\u63d0\u793a\u5b57\u7b26\u4e32\uff0c\u7136\u540e\u518d\u628a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u8fd4\u56de\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u4e0d\u4fee\u6539\u5199GuessNum\uff0c\u800c\u662f\u4ece\u5b83\u57fa\u7840\u4e0a\u6d3e\u751f\u4e00\u4e2a\u65b0\u7c7b\uff0c\u8fd9\u4e2a\u5de5\u4f5c\u7559\u7ed9\u4f60\u81ea\u5df1\u53bb\u8bd5\u9a8c\u3002<\/p>\n<p>\u8bf4\u7684\u5f88\u5bb9\u6613\uff0c\u505a\u8d77\u6765\u5462\uff1f\u4e5f\u4e0d\u96be\uff01\u4f60\u4e0d\u7528\u62c5\u5fc3\u8981\u81ea\u5df1\u7528WinSock\u5199\u4e00\u4e2a\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u53bb\u8bbf\u95eeWeb Service\uff0c\u5e76\u81ea\u5df1\u5bf9\u8fd4\u56de\u7684XML\u6587\u4ef6\u8fdb\u884c\u5904\u7406\uff0c\u8fd9\u4e9b\u5de5\u4f5cVisual Studio.NET\u5df2\u7ecf\u5e2e\u6211\u4eec\u505a\u597d\u4e86\uff01<\/p>\n<p>\u5728Visual Studio.NET\u96c6\u6210\u754c\u9762\u7684\u53f3\u4e0a\u89d2\u6709\u4e00\u4e2aSolution Explorer\uff0c\u6211\u4eec\u7528\u9f20\u6807\u5728\u91cc\u9762\u7684Reference\u4e0a\u53f3\u952e\u5355\u51fb\uff0c\u7136\u540e\u9009\u62e9\u201cAdd Web Reference\u201d\u6765\u6dfb\u52a0\u4e00\u4e2a\u5bf9Web Service\u7684\u5f15\u7528\u3002<\/p>\n<div id=\"attachment_937\" style=\"width: 226px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424j\" rel=\"attachment wp-att-937\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-937\" class=\"size-full wp-image-937\" title=\"\u6dfb\u52a0Web\u5f15\u7528\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424J.jpg\" alt=\"\u6dfb\u52a0Web\u5f15\u7528\" width=\"216\" height=\"320\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424J.jpg 216w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424J-202x300.jpg 202w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/><\/a><p id=\"caption-attachment-937\" class=\"wp-caption-text\">\u6dfb\u52a0Web\u5f15\u7528<\/p><\/div>\n<p>\u5728\u5f39\u51fa\u7684Add Web Reference\u5bf9\u8bdd\u6846\u7684\u5730\u5740\u680f\u4e2d\u8f93\u5165\u524d\u9762\u8bb0\u5f55\u4e0b\u6765\u7684\u5730\u5740\uff0c\u56de\u8f66\u3002\u7b49\u51fa\u73b0\u4e86Web Service\u7684\u6d4b\u8bd5\u9875\u9762\u540e\uff0c\u70b9\u51fb\u201cAdd Reference\u201d\u6309\u94ae\u3002<\/p>\n<div id=\"attachment_938\" style=\"width: 387px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\/020424k\" rel=\"attachment wp-att-938\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-938\" class=\"size-full wp-image-938\" title=\"\u6dfb\u52a0Web Reference\" src=\"\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424K.jpg\" alt=\"\u6dfb\u52a0Web Reference\" width=\"377\" height=\"260\" srcset=\"https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424K.jpg 377w, https:\/\/www.freemindworld.com\/blog\/wp-content\/uploads\/2002\/04\/020424K-300x206.jpg 300w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/a><p id=\"caption-attachment-938\" class=\"wp-caption-text\">\u6dfb\u52a0Web Reference<\/p><\/div>\n<p>\u8fd9\u65f6\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u770b\u5230\u5728Solution Explorer\u4e2d\u65b0\u51fa\u73b0\u4e86\u4e00\u4e2aWeb Reference\uff0c\u91cc\u9762\u6709\u6211\u4eec\u7684Web Service\u3002\u5176\u5b9e\uff0c\u6211\u4eec\u901a\u8fc7Visual Studio.NET\u7684\u5e2e\u52a9\u7528\u8fd9\u6837\u7b80\u5355\u7684\u64cd\u4f5c\u5b8c\u6210\u7684\u662f\u4e00\u7cfb\u5217\u7684\u5de5\u4f5c\u3002\u9996\u5148\u662f\u6839\u636e\u8f93\u5165\u5730\u5740\u4ece\u670d\u52a1\u5668\u4e0a\u83b7\u53d6WSDL\uff0c\u7136\u540e\u518d\u6839\u636eWSDL\u7684\u63cf\u8ff0\u751f\u6210\u4e00\u4e2aC#\u7684\u4ee3\u7406\u7c7b\uff08Proxy Class\uff09\uff0c\u7136\u540e\u518d\u628a\u5b83\u6dfb\u5230\u5de5\u7a0b\u4e2d\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u65b9\u4fbf\u7684\u4f7f\u7528\u8fd9\u4e2a\u7c7b\uff0c\u6765\u4f7f\u6211\u4eec\u7684\u7a0b\u5e8f\u4e0eWeb Service\u8054\u7cfb\u8d77\u6765\uff0c\u5b8c\u6210\u6211\u4eec\u7684\u9700\u8981\u7684\u64cd\u4f5c\u3002<\/p>\n<p>\u4e0b\u9762\u53ef\u4ee5\u771f\u6b63\u4fee\u6539GuessNum\u7684GetTip()\u7684\u4ee3\u7801\u4e86\u3002\u9996\u5148\uff0c\u6211\u4eec\u5728\u7a0b\u5e8f\u6e90\u4ee3\u7801\u7684\u6700\u524d\u9762\u52a0\u5165\uff1a<\/p>\n<p><strong>using<\/strong> GuessNumFinal.localhost;<\/p>\n<p>\u5f15\u7528\u4e00\u4e0b\u6211\u4eec\u8fd9\u4e2aWeb Service\u7684\u4ee3\u7406\u7c7b\u6240\u5728\u7684\u540d\u5b57\u7a7a\u95f4\uff0c\u4ee5\u65b9\u4fbf\u6211\u4eec\u540e\u9762\u4ee3\u7801\u7684\u4e66\u5199\u3002\uff08\u5982\u679c\u4f60\u4e0d\u662f\u65b0\u5efa\u4e86GuessNumFinal\u9879\u76ee\uff0c\u800c\u662f\u5728GuessNum2\u7684\u57fa\u7840\u4e0a\u4fee\u6539\u7684\u8bdd\uff0c\u8bf7\u628a\u4e0a\u9762\u7684GuessNumFinal\u6539\u6210GuessNum2\u3002\uff09<\/p>\n<p>\u63a5\u4e0b\u6765\u628aGuessNum\u7c7b\u7684GetTip()\u65b9\u6cd5\u6539\u6210\u5982\u4e0b\u7684\u4ee3\u7801\uff1a<\/p>\n<p><strong>public<\/strong> <strong><span style=\"color: blue;\">string<\/span><\/strong> GetTip(<strong><span style=\"color: blue;\">string<\/span><\/strong> answer)<\/p>\n<p>{<\/p>\n<p>     Service1 service = <strong><span style=\"color: blue;\">new<\/span><\/strong> Service1(); <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u7528<\/span>GuessNumFinal.localhost<span style=\"color: green; font-family: Fixedsys;\">\u540d\u5b57\u7a7a\u95f4\u4e2d\u7684<\/span>Service1<span style=\"color: green; font-family: Fixedsys;\">\u7c7b\u751f\u6210\u4e00\u4e2a\u5bf9\u8c61<\/span><\/p>\n<p>     <strong><span style=\"color: blue;\">return<\/span><\/strong> service.GetTip(correctAnswer, answer); <span style=\"color: green;\">\/\/<\/span><span style=\"color: green; font-family: Fixedsys;\">\u547c\u53eb<\/span>Web Service<span style=\"color: green; font-family: Fixedsys;\">\uff0c\u5f97\u5230\u8fd4\u56de\u503c\u540e\u8fd4\u56de<\/span><\/p>\n<p>}<\/p>\n<p>\u6700\u540e\uff0c\u627e\u5230Form1_Load()\u65b9\u6cd5\u4e2d\u7684<\/p>\n<p>textBox2.Text = gn.GenerateRandomNumber();<\/p>\n<p>\u628a\u5b83\u6539\u6210\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u4e0d\u518d\u9700\u8981\u5077\u770b\u7b54\u6848\u4e86\uff01<\/p>\n<p>textBox2.Text = &#8220;&#8221;;<\/p>\n<p>gn.GenerateRandomNumber();<\/p>\n<p>\u81f3\u6b64\uff0c\u6211\u4eec\u7a0b\u5e8f\u7ec8\u4e8e\u5b8c\u6210\u4e86\uff01\u6309\u4e0bF5\u8fd0\u884c\u7a0b\u5e8f\uff0c\u6765\u4f53\u9a8c\u4e00\u4e0b\u81ea\u5df1\u7528.NET\u7f16\u5199\u7684\u7b2c\u4e00\u4e2a\u6e38\u620f\u7a0b\u5e8f\uff01<\/p>\n<p align=\"center\">   <span style=\"font-size: 16pt; font-family: \u534e\u6587\u65b0\u9b4f;\">\u4f53\u9a8cMicrosoft .NET\u4e4b\u7ed3\u5c3e\u7bc7<\/span><\/p>\n<p>\u6211\u4eec\u7684\u731c\u6570\u5b57\u6e38\u620f\u505a\u5b8c\u4e86\uff0c\u6211\u4eec\u7684.NET\u4e4b\u65c5\u4e5f\u5c06\u63a5\u8fd1\u5c3e\u58f0\u3002\u4f5c\u4e3a\u5fae\u8f6f\u516c\u53f8\u4e00\u4e2a\u5168\u65b0\u7684\u5e73\u53f0\uff0c\u867d\u7136\u76ee\u524d\u6709\u5173.NET\u7684\u4e89\u8bba\u8fd8\u5f88\u591a\uff0c\u4f46\u5f88\u591a\u4eba\u8fd8\u662f\u76f8\u4fe1.NET\u4f1a\u5728\u5fae\u8f6f\u516c\u53f8\u7684\u5927\u529b\u652f\u6301\u4e0b\u8d8a\u6765\u8d8a\u6210\u719f\uff0c.NET\u5b9a\u5c06\u6210\u4e3a\u5fae\u8f6f\u5e73\u53f0\u8f6f\u4ef6\u5f00\u53d1\u4e00\u4e2a\u91cc\u7a0b\u724c\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9\u5927\u5bb6\u66f4\u597d\u7684\u53bb\u4e86\u89e3\u548c\u5b66\u4e60.NET\uff0c\u6700\u540e\u6211\u5728\u4e0b\u9762\u5217\u51fa\u4e00\u4e9b\u597d\u7684\u53c2\u8003\u8d44\u6599\u4f9b\u5927\u5bb6\u53c2\u8003\uff1a<\/p>\n<p>1.<span style=\"font: 7pt 'Times New Roman';\">    <\/span>\u5305\u542b\u5728.NET Framework SDK\u4e2d\u7684Samples and QuickStart Tutorials<\/p>\n<p>2.<span style=\"font: 7pt 'Times New Roman';\">    <\/span>\u5305\u542b\u5728Visual Studio.NET \u4e2d\u7684Microsoft Visual Studio .NET Documentation<\/p>\n<p>3.<span style=\"font: 7pt 'Times New Roman';\">    <\/span>\u5fae\u8f6f\u516c\u53f8\u7f51\u7ad9\uff0cMSDN\u7f51\u7ad9<\/p>\n<p>4.<span style=\"font: 7pt 'Times New Roman';\">    <\/span><a href=\"http:\/\/www.cndot.net\/\">http:\/\/www.cndot.net<\/a>\u7b49\u56fd\u5185\u5916.NET\u6280\u672f\u7f51\u7ad9<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f53\u9a8c \u5fae\u8f6f\u516c\u53f8\u6b63\u5728\u9886\u5bfc\u4e00\u6b21\u65b0\u7684\u4e92\u8054\u7f51\u6280\u672f\u9769\u547d\uff0c\u8fd9\u5c31\u662f.NET\u3002.NET\u662f\u4e00\u79cd\u5168\u65b0 &hellip; <a href=\"https:\/\/www.freemindworld.com\/blog\/2002\/020424_experience_dotnet.shtml\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-117","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/comments?post=117"}],"version-history":[{"count":5,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions"}],"predecessor-version":[{"id":942,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/posts\/117\/revisions\/942"}],"wp:attachment":[{"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/media?parent=117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/categories?post=117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freemindworld.com\/blog\/wp-json\/wp\/v2\/tags?post=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}