0

「$mcsfile.cs」を使用してc#ファイルをコンパイルしようとすると、「エラーCS0103:現在のコンテキストに「HttpUtility」という名前が存在しません」というエラーが発生します。「usingSystem.Web」を追加し、モノフレームワークを使用してSuse12.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 に答える