任何人都可以幫助新手C#初學者嗎?我試圖調用在同一個類中創建的對象,但使用了不同的方法。兩種方法都是從另一個班級調用的。下面是簡單的代碼。我遺漏了方法執行的其他代碼。錯誤表示在第二種方法中不能識別「偵聽器」對象。感謝您提供的任何幫助。如何從C#中的另一種方法調用對象#
// this 1st class calls methods of a 2nd class
public class Lru_operation
{
// create an object of the 2nd class
public Lru_Listen LruListen = new Lru_Listen();
// this method calls two methods from other class
public void LruOperation()
{
LruListen.ListenForAag(); // first method call
LruListen.LruListenAccReq(); // second method call
}
}
// this is the 2nd class
public class Lru_Listen
{
// 1st method creates an object from a different class (HttpListener)
public void ListenForAag()
{
HttpListener listener = new HttpListener();
}
// 2nd method calls 1st method's object to perform
// a method task from a different class
public void LruListenAccReq()
{
HttpListenerContext context = listener.Getcontext();
}
}
[ಠ_ಠ](http://damnyourfastfingers.com) – Will