Hinweis: Diese von WebBrowser Event Properties?Warum kann ich nicht auf die Mitglieder eines Ereignisses zugreifen, das einem anderen Typ angehört?
inspiriert Warum bin ich in der Lage, die MulticastDelegate
Mitglieder eines Ereignisses innerhalb des Typs zuzugreifen, die das Ereignis davon aber nicht außerhalb erklärt?
Zum Beispiel:
using System;
class Bar
{
public static event Action evt;
}
class Program
{
static event Action foo;
static Bar bar;
static void Main()
{
// this works
Delegate[] first = foo.GetInvocationList();
// This does not compile and generates the following
// error:
//
// The event 'Bar.evt' can only appear on the
// left hand side of += or -= (except when used
// from within the type 'Bar')
Delegate[] second = bar.evt.GetInvocationList();
}
}
Ich habe das Gefühl, das ist etwas sehr einfach ist, dass ich nicht zu sehen bin.
+1 Das macht Sinn - danke! –