Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Dynamic didn’t really go anywhere, but more appropriate examples that have now pervaded the language are await in general and IDisposable for ref struct. If it has a GetAwaiter it can be awaited, with no interface. If it has a Dispose() it can be disposed with no interface.


Interestingly, this sort of structural typing was already present in C# 1.0 with the foreach statement allowing anything with a GetEnumerator() method that returns something that looks like an IEnumerator.

This was discussed in 2011 in a StackOverflow question [0], including a link to a blog post by one of the language designers [1].

[0] https://stackoverflow.com/questions/6368967/duck-typing-in-t...

[1] https://web.archive.org/web/20120126033827/http://blogs.msdn...


As far as I understand it it went to wherever there are still poor souls writing COM Interop stuff primarily. Luckily I've never had to touch it so outside of Dapper for SQL I've never really had cause to use dynamic. I imagine there are Windows shops using it heavily though.


> If it has a GetAwaiter it can be awaited, with no interface. If it has a Dispose() it can be disposed with no interface.

I don't know much about C# but how is this dynamic? Are those methods often added at runtime?


It's not dynamic. It is structural typing




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: