Add event initializer #8327
-
When we initialize an object with event, we need to write class A
{
public event Action Event;
}
A a = new A();
a.Event += () => {};
a.Event += () => {}; But if we need to initialize someting in initializer, we have to write class A
{
public A Child { get; set; }
public event Action Event;
}
A child = new A();
child.Event += () => {};
child.Event += () => {};
A host = new A
{
Child = child
};
child.Event += () => {};
child.Event += () => {}; So if we have event initializer, we can write it like class A
{
public A Child { get; set; }
public event Action Event;
}
A a = new A
{
Child = new A
{
Event =
{
() => {},
() => {}
}
},
Event =
{
() => {},
() => {}
}
} The event is like a delegate collection which both have |
Beta Was this translation helpful? Give feedback.
Answered by
HaloFour
Aug 1, 2024
Replies: 1 comment 1 reply
-
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
333fred
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: #307 and #5176