How do i cast an object to a string when object is not a string?
- by acidzombie24
I have class A, B, C. They all can implicitly convert to a string
public static implicit operator A(string sz_) { ... return sz; }
I have code that does this
object AClassWhichImplicitlyConvertsToString
{
...
((KnownType)(String)AClassWhichImplicitlyConvertsToString).KnownFunc()
}
The problem is, AClassWhichImplicitlyConvertsToString isnt a string even though it can be typecast into one implicitly. I get a bad cast exception. How do i say its ok as long as the class has an operator to convert into a string?