خروجیهای Covariant به زودی در NET runtime.
نویسنده: وحید نصیری
تاریخ: ۱۳۹۹/۰۲/۱۹ ۸:۱۳
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
Work in progress to add support for covariant return types to the .NET runtime. Soon we'll be able to override a virtual method returning `object` with a method returning `string`. Because of how array variance works, weird things might be possible in IL.
class Base
{
public virtual IntPtr[] Fun() => null;
}
// This is obvious pseude-code because C# won't let us introduce methods differing
// in return type. C# also requires to be explicit about "virtual" and "override".
// But IL... not so much.
class Derived : Base
{
// overrides Base.Fun on 32bit platforms.
public override uint[] Fun() => null;
// overrides Base.Fun on 64bit platforms.
public override ulong[] Fun() => null;
}