1
我可以訪問包含委託內委託的對象嗎?c#從委託函數訪問所有者對象
例如
class Salutation {
public string OtherParty {get; set;}
public AddressDelegate GreetingDelegate {get; set;}
}
public delegate void AddressDelegate();
則...
void Main() {
Salutation hello = new Salutation {
OtherParty = "World",
GreetingDelegate = new AddressDelegate(HelloSayer)
};
hello.GreetingDelegate();
}
private void HelloSayer() {
Console.WriteLine(string.Format("Hello, {0}!", OtherParty));
}
所以是有可能的HelloSayer
函數內參照OtherParty
財產的稱呼類的,或者我需要傳遞數據作爲參數傳遞給功能?