0

It's a textbook example. You can explain work of it.

сlass C { int i; public C (int i) { this. i = i;} public static explicit operator C (string s> { return new C (int. Parse(s)) ; } } object o = "1'; dynamic d =" 2"; var c1 = (C) o; //error var c2 = (C) d;

7th Dec 2017, 10:18 PM
Валерия
Валерия - avatar
1 Respuesta
+ 1
Explicit operator used to convert something to class where you declare it. In this case operator c will convert string to int. But here object o = "1'; there are single quot instead of dual used, this is probably why var c1 = (C) o; statement marked with error.
7th Dec 2017, 11:21 PM
Dima Makieiev
Dima Makieiev - avatar