c# - Why doesn't Enumerable.Cast<> use my conversion operator? -
using type:
class foo { public static implicit operator int(foo obj) { return 5; } } var test=new[] { new foo() };
the following works expected
var ok=test.select(x => (int)x).tolist();
but using cast<> fails invalidcastexception - why?
var fail=test.cast<int>().tolist();
read jon skeet's blog reimplementing linq (edulinq), part 33, says this:
it's worth noting (as of .net 3.5 sp1) cast , oftype perform reference , unboxing conversions. won't convert boxed int long, or execute user-defined conversions. follow same rules converting object generic type parameter. (that's convenient implementation!)
Comments
Post a Comment