Reputation: 1176
I have got some BankAccount like below.
My question is using instance of BankAccount class, I can access the ActionDelegate delegate declared in the class but the not BalanceChangedEventHandler delegate defined in the class?
public class BankAccount
{
public Action<int> ActionDelegate;
public delegate void BalanceChangedEventHandler(object sender, BalanceChangedEventArgs args);
public event BalanceChangedEventHandler BalanceChanged;
}
Upvotes: 3
Views: 81
Reputation: 1235
You can access the delegate via the class name not an instance of this class
so you have to write
BankAccount.BalanceChangedEventHandler
Upvotes: 0
Reputation: 172280
(emphasis mine)
... using instance of BankAccount class, I can access [...] but the not BalanceChangedEventHandler delegate defined in the class?
Delegate declarations don't have state. Thus, you don't access them through the instance, you access them like a nested class declaration:
myBankAccount.BalanceChangedEventHandler // won't work
BankAccount.BalanceChangedEventHandler // works
Upvotes: 2