2010-11-11 65 views
5

我是新來的C#。我有這個類...如何訪問GetGlobalResourceObject()

using System; 
using System.Data; 
using System.Configuration; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 


public class clsErrorMessages 
{ 
    string _sErrors; 
    public clsErrorMessages(string sErrorTextFileName) 
    { 
     _sErrors = (String)GetGlobalResourceObject("resource","FriendlyErrors.txt"); 

    } 
} 

編譯器說:the name 'GetGlobalResourceObject' does not exist in the current context

我需要包括另一個using

回答

7

GetGlobalResourceObject()方法是HttpContext類的靜態成員。您需要對其進行限定:

_sErrors = (string) HttpContext.GetGlobalResourceObject("resource", 
    "FriendlyErrors.txt"); 
+0

Thanks!這已經擺脫了錯誤。如何智能感知不會讓我像「System.Web.HttpContext」或類似的遍歷層次結構? – 2010-11-11 11:38:50

+0

我不知道我明白。 「遍歷層次結構」是什麼意思? – 2010-11-11 11:43:11

+0

我的意思是什麼'HttpContext'的成員?不應該一切都在'System'之下嗎? – 2010-11-11 13:58:21