C
Join ServerC#
help
❔ How do generic parameters with static classes work?
Aaugh1/28/2023
Like if I have code like below, will a new Handle exist for every generic type used?

Tthinker2271/28/2023
yes
Aaugh1/28/2023
This is weird
Aaugh1/28/2023
This conflicts with my understanding of c#
Tthinker2271/28/2023
EventBroadcast<Func<int, int>>
and EventBroadcast<Action<int>>
are different types, so their members are completely separateAaugh1/28/2023
My understanding was that static variables can only exist once.
Aaugh1/28/2023
And to have multiple variables of different types you'd need instances
Aaugh1/28/2023
Are there any downsides to doing it like this?
Aaugh1/28/2023
How does the garbage collector know when to collect Handle
Tthinker2271/28/2023
Tthinker2271/28/2023
Well, the GC doesn't collect the property
Handle
, it collects the value of Handle
Tthinker2271/28/2023
When you set
Handle
to a new value, the old value gets GC'd (it there are no more referenced to it anywhere)Aaugh1/28/2023
And if I input another type for T it creates another instance of Handle
Tthinker2271/28/2023
This is also still true. Again,
EventBroadcast<Func<int>>
and EventBroadcast<Action>
are different types. EventBroadcast<Func<int>>.Handle
and EventBroadcast<Action>.Handle
both only exist once.Aaugh1/28/2023
ok
AAccord1/29/2023
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.