C
C#2y ago
augh

❔ How do generic parameters with static classes work?

Like if I have code like below, will a new Handle exist for every generic type used?
9 Replies
Thinker
Thinker2y ago
yes
augh
aughOP2y ago
This is weird This conflicts with my understanding of c#
Thinker
Thinker2y ago
EventBroadcast<Func<int, int>> and EventBroadcast<Action<int>> are different types, so their members are completely separate
augh
aughOP2y ago
My understanding was that static variables can only exist once. And to have multiple variables of different types you'd need instances Are there any downsides to doing it like this? How does the garbage collector know when to collect Handle
Thinker
Thinker2y ago
Well, it's static so it'd never be collected Well, the GC doesn't collect the property Handle, it collects the value of Handle When you set Handle to a new value, the old value gets GC'd (it there are no more referenced to it anywhere)
augh
aughOP2y ago
And if I input another type for T it creates another instance of Handle
Thinker
Thinker2y ago
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.
augh
aughOP2y ago
ok
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server