You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use the collection initializer of a HashSet you end up with an empty HashSet, which I guess is the case because it is an immutable collection, but since I am creating the collection at that point in time and not modifying it after creation I was surprised to see my HashSet was empty. The thing is that this compiles just fine but at runtime the HashSet is empty. Below a comparison between the System and LangExt versions of the type:
There’s nothing I can do about that (as far as I am aware), this is a flaw in C#’s collection initialisation system. I believe it calls Add after construction, but obviously it’s an immutable collection. The crux of it is that you can’t use this.
Ahh I thought something like that was the case, thanks for the explanation! The analyzer would be helpful indeed. Maybe we should tag this issue as documentation for visibility? Anyway, I will close this issue.
Hi!
When you use the collection initializer of a HashSet you end up with an empty HashSet, which I guess is the case because it is an immutable collection, but since I am creating the collection at that point in time and not modifying it after creation I was surprised to see my HashSet was empty. The thing is that this compiles just fine but at runtime the HashSet is empty. Below a comparison between the System and LangExt versions of the type:
I don't know if this is intended behavior or a bug, but it sure is confusing :P
(running the latest version of LangExt btw)
The text was updated successfully, but these errors were encountered: