我對以下幾點感到困惑。C#.net鑄造問題
鑑於這種類:
public class SomeClassToBeCasted
{
public static implicit operator string(SomeClassToBeCasted rightSide)
{
return rightSide.ToString();
}
}
當我嘗試做以下爲什麼一個InvalidCastException拋出?
IList<SomeClassToBeCasted> someClassToBeCastedList
= new List<SomeClassToBeCasted> {new SomeClassToBeCasted()};
IEnumerable<string> results = someClassToBeCastedList.Cast<string>();
foreach (var item in results)
{
Console.WriteLine(item.GetType());
}
而且,添加,就可以得到 「繞」 這跟'的IEnumerable結果= someClassToBeCastedList.Select(X =>(串)X);' –
jason
2010-01-14 16:14:12