Cast to var #8803
Replies: 5 comments
-
This looks like For upcasting, it's recommended to use a helper method T StaticCast<T, TDerived>(TDerived o) where TDerived : T => o; But now you need to specify all type arguments. While partial type inference (#1349) could help with that, you could hide static class StaticCast<T> {
static T From<TDerived>(TDerived o) where TDerived : T => o;
} But once we have type inference from target-type (#92) you could use the original method with all type arguments inferred: x = Cast(y); // Cast<int, object>(y) which will work for upcasting as well. |
Beta Was this translation helpful? Give feedback.
-
Why not write it even shorter: x = ()y; for target-typed explicit cast. |
Beta Was this translation helpful? Give feedback.
-
x = y; ? What is this, VB? ;)
…On Fri, Sep 27, 2019, 9:08 AM setbbtjl8wwq ***@***.***> wrote:
@ronnygunawan <https://github.com/ronnygunawan> or even ;)
x = y;
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#2827?email_source=notifications&email_token=AAT52GQAQ3BXNSU5E6DFBCLQLYATLA5CNFSM4I23J7T2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7Y2UVI#issuecomment-535931477>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAT52GQKUBKY7TKK5PKEW3TQLYATLANCNFSM4I23J7TQ>
.
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This would be a shortcut for casting to the type of a variable - for instance
the cast would be equivalent to
(int)y
becausex
is of typeint
.Beta Was this translation helpful? Give feedback.
All reactions