i've written the following class:
public class A
public static implicit operator A(B instance)
return new A(instance);
However, when i create a List<B> and call Cast<A>().ToList() i get a runtime error saying "Unable to cast object of type 'B' to type 'A'". However, when i do a simple implicit, or explicit, cast from B to A it works fine.
Sunday, January 27, 2008 11:17 PM
specifically? are you sure?
it's called Cast, surely it should consider custom cast operations. It's not that difficult.
I'm not a regular to these forums. Do members of the LINQ team visit these forums?
Could you concider this for the next release?
Thanks for the work-around tho.Sunday, January 27, 2008 11:45 PM
Here's a discussion from this forum about this change.
Note that Cast's behavior changed from 3.5 to 3.5SP1, so you could have code that breaks if you test in one but not the other.Wednesday, January 21, 2009 5:50 AM