How do i cast an object to a string when object is not a string?
Posted
by acidzombie24
on Stack Overflow
See other posts from Stack Overflow
or by acidzombie24
Published on 2010-03-21T10:58:57Z
Indexed on
2010/03/21
11:01 UTC
Read the original article
Hit count: 231
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?
© Stack Overflow or respective owner