【发布时间】:2010-12-07 11:43:24
【问题描述】:
我正在尝试从存储过程的结果转换为 List .. 我已经为 timerangeResult -> Booking 的单个对象创建了显式(工作)转换,但我缺少一个列表..
代码如下:
public static explicit operator List<Booking>(timerangeResult t)
{
List<Booking> bL = new List<Booking>();
IEnumerable<timerangeResult> tx = (IEnumerable<timerangeResult>) t;
foreach (timerangeResult tt in tx)
{
Booking b = (Booking)tt;
bL.Add(b);
}
//return bL;
//return new List<Booking>(bL);
//return new List<Booking>(IEnumerable < Booking > bL);
return bL;
// [NONE OF THESE WORK]
// ERROR:
// User-defined conversion must convert to or from the enclosing type (UNDERLINED: "explicit operator List<Booking>" line 1)
}
提前致谢!
【问题讨论】:
-
真的很奇怪的代码,你把
timerangeResult转换成IEnumerable<timerangeResult>。