2013-04-01 102 views
1

我正在使用Asp.Net 2.0.I試圖構建一個應用程序如何構建一個Store Locator ASP.NET Application Using Google Maps API。當我嘗試使用「var 「在應用程序中出現錯誤」無法找到類型或名稱空間名稱'var'(您是否缺少using指令或程序集引用?)「。無法在asp.net 2.0中找到類型或命名空間名稱'var'

我已經下載了上面的文章,並在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' 
+0

var直到C#3.0才被引入。 http://msdn.microsoft.com/en-us/library/bb383973.aspx – Ricky

回答

0

var關鍵字不可用於.NET 2.0(C#2.0)。

它僅在C#3.0以上版本中可用。這是C#語言功能,在舊版本中不可用。

+0

我已經下載並安裝.net3.5框架在我的web.config.Will它有所作爲。 – Kannan

+0

另外我已經下載了上述應用程序中提供的代碼,並且其工作完美。 – Kannan

相關問題