0

当我尝试使用“$ mcs file.cs”编译我的 c# 文件时,我收到此错误“错误 CS0103:当前上下文中不存在名称‘HttpUtility’”。我添加了“使用 System.Web”,并使用单声道框架在 Suse 12.1 上运行它。我是 C# 的新手,正在学习这里的教程http://www.codeproject.com/Articles/9407/Introduction-to-Mono-Your-first-Mono-app

这是我的 file.cs 中的代码

using System;
using System.Net;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;

namespace Dela.Mono.Examples
{
        class GoogleSearch
         {
                static void Main(string[] args)
                 {
                        Console.Write("Please enter a string to search google for:");
                        string searchString = HttpUtility.UrlEncode(Console.ReadLine());

                        Console.WriteLine();
                        Console.Write("Please wait....\r");

                        //Query google
                        WebClient webClient = new WebClient();
                        byte[] response =     webClient.DownloadData("http://www.google.com/search?&num=5&q=" + searchString);


                        //Check reponse results
                        string regex = "g><a\\shref=\"?(?<URL>[^\">]*)[^>]*>(?<Name>[^<]*)";
                        MatchCollection matches = Regex.Matches(Encoding.ASCII.GetString(response), regex);

                        //output results
                        Console.WriteLine("===== Results =====");
                                 if(matches.Count > 0)
                                 {
                                        foreach(Match match in matches)
                                        {
                                                 Console.WriteLine(HttpUtility.HtmlDecode(
                                                        match.Groups["Name"].Value) +
                                                        " - " + match.Groups["URL"].Value);
                                        }
                                 }
                                 else
                                 {
                                        Console.WriteLine("0 results found");
                                 }
                } 
        }
}

可能是什么问题,我该如何解决?

4

1 回答 1

1

如您链接到的文章中所述,尝试编译:

$ mcs file.cs -r System.Web.dll
于 2012-10-19T07:23:25.587 回答