Enhance as
or/and is
operators is a good idea?
#6257
-
Scenario: public class A {
public static implicit operator B (A a) => ...;
}
public class B { }
var a = new A();
var b = a as B;
if(a is B b) Actual: var a = new A();
var b = a as B; /* error CS0039 */
if (a is B b) { /* error CS8121 */ } Is this a bad idea? |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Jul 6, 2022
Replies: 2 comments
-
See #1248 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
orlys
-
The alternative is not reflection, the alternative is: var a = new A();
var b = (B)a;
// 'if' makes no sense because it is a runtime check, but it statically known that A can be cast to B. |
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
See #1248