我正在使用Asp.Net 2.0。我正在尝试构建一个关于如何构建Store Locator ASP.NET Application Using Google Maps API的应用程序。当我尝试在应用程序中使用“var”时,它会给出错误“类型或命名空间找不到名称'var'(您是否缺少using指令或程序集引用?)“。
我已经下载了上面的文章并在vs2005中正常工作。我想知道为什么错误只出现在我的项目中?
我在应用程序中使用的命名空间
using System;
using System.Collections.Generic;
using System.Web;
using System.Xml.Linq;
using System.Linq;
继承我使用过的课程
public static XElement GetGeocodingSearchResults(string address)
{
// Use the Google Geocoding service to get information about the user-entered address
// See http://code.google.com/apis/maps/documentation/geocoding/index.html for more info...
var url = String.Format("http://maps.google.com/maps/api/geocode/xml?address={0}&sensor=false", HttpContext.Current.Server.UrlEncode(address));
// Load the XML into an XElement object (whee, LINQ to XML!)
var results = XElement.Load(url);
// Check the status
var status = results.Element("status").Value;
if (status != "OK" && status != "ZERO_RESULTS")
// Whoops, something else was wrong with the request...
throw new ApplicationException("There was an error with Google's Geocoding Service: " + status);
return results;
}
我得到的错误如下
Error 1 : The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)
Error 2 : The best overloaded method match for 'System.Xml.Linq.XElement.Load(string)' has some invalid arguments
Error 3:cannot convert from 'var' to 'string'