Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#8 handle ref strucs #148

Open
JohanLarsson opened this issue Jan 24, 2019 · 1 comment
Open

C#8 handle ref strucs #148

JohanLarsson opened this issue Jan 24, 2019 · 1 comment

Comments

@JohanLarsson
Copy link
Collaborator

Ref structs can now be disposable without implementing the IDisposable interface, simply by having a Dispose method in them.
https://blogs.msdn.microsoft.com/dotnet/2019/01/24/do-more-with-patterns-in-c-8-0/

@jnm2
Copy link

jnm2 commented Dec 17, 2019

So for C# 8, types are disposable with using if:

  • IDisposable is implemented, implicitly or explicitly
  • Or, the type is a ref struct and public instance Dispose() exists and returns void

And types are disposable with await using if:

  • IAsyncDisposable is implemented, implicitly or explicitly
  • Or, public instance DisposeAsync() exists and returns an awaitable type with a void result (not just ValueTask)

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants