Closed abelbraaksma closed 5 years ago
Issue fixed in #10392 - @abelbraaksma if you have an idea for a different sample, we'd definitely love the PR.
@cartermp, I worked a bit with the idea I posted, i.e. the IComparable
on the fly. But I couldn't make a trivial worked out example. I'll give it another go, I might not have understood this syntax enough back then
The example code with the object expression for
IFormattable
doesn't work, for instance, in FSI, it prints the following:> "{FSI_0002+Delimiter@1}"
The reason this happens is the wrong assumption that the this-qualifier holds anything useful (like a string or a number) but since object expressions aren't assignable, as written it is a poor example of showcasing the usefulness.
In fact, I think that a note on the what the this-qualifier points to in such cases would be useful. As far as I know, it is only somewhat useful when you use a base class, instead of an interface, as with a base class at least it points to its instance.
While at the subject, perhaps we can improve the examples here a bit? For instance with a few real-world use-cases like implementing
IComparable
on the fly, or a combination of both interfaces and class. Also, an example show-casing using thegeneric-type-params
from the syntax is missing.I could come up with some examples if this is considered useful.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.