❔ 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
yes
This is weird
This conflicts with my understanding of c#
EventBroadcast<Func<int, int>>
and EventBroadcast<Action<int>>
are different types, so their members are completely separateMy 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
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)And if I input another type for T it creates another instance of Handle
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.ok
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.