Allow direct casting between type parameters and all types #8812
Unanswered
ekolis
asked this question in
Language Ideas
Replies: 2 comments
-
The compiler can't validate the cast. The fact that you did an In this case you can use pattern matching and eliminate the need for the cast: public string DoStuff<T>(T t)
{
if (t is decimal d)
{
Console.WriteLine("the number is: " + d);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Interestingly enough, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have this:
This code does not compile because
T
cannot be cast directly todecimal
; I have to do an intermediate cast toobject
(void*
much?!):Seems rather unnecessary to me... why can't I cast the type parameter instance directly to whatever type I want?
Beta Was this translation helpful? Give feedback.
All reactions