当我尝试使用“$ 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");
}
}
}
}
可能是什么问题,我该如何解决?