I hereby claim:
- I am John-Paul-R on github.
- I am john_paul_r (https://keybase.io/john_paul_r) on keybase.
- I have a public key whose fingerprint is 522F F5DE A709 6C4A AD1A 3BEC 7B98 1822 047F E953
To claim this, I am signing this object:
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net7.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> |
I hereby claim:
To claim this, I am signing this object:
I think what might clarify is how events work. (Note, this is a long answer, tailored to your example. For something shorter, but less specific, see https://stackoverflow.com/a/33964976/8105643)
The event
keyword is really just a nice syntax for setting up an EventHandler Delegate.
Now we understand that events are just special syntax delegates, we can explain how subscribing to an event actually works, and show how the two examples you gave are actually quite similar:
In your first example, you have essentially this situation:
public class DelegateCombineExample {
doing an operation on two numbers will give you a different output type depending on what the types of the operands are.
+
) or division (/
).for example, in 3 - 2
, 3 is the first operand, 2 is the second operand, and subtraction (-
) is the operation.
For our case, we're working with 2 types: