我广泛使用ArrayList并且难以使用此列表<>。我正在使用EntitySpace ORM做DAL的东西。这个东西很好用,但问题是,我不得不定义列表<>与抱怨它不能转换的对象类型。用C#中的List <>替换ArrayList
我很感谢您的帮助。
原使用的ArrayList:
public ArrayList Get()
{
TndCustomerTendersCollection collection = new TndCustomerTendersCollection();
collection.Query
.Select
(
collection.Query.CustomerTenderID,
collection.Query.CustomerTenderID,
collection.Query.CustomerTenderCode,
collection.Query.CustomerTenderName,
collection.Query.StartDate,
collection.Query.DueDate,
collection.Query.CompleteDate,
collection.Query.DateCreated,
collection.Query.LastDateModified
)
.Where
(
collection.Query.IsActive.Equal(true)
);
ArrayList list = new ArrayList();
foreach (TndCustomerTenders item in collection)
{
list.Add(item);
}
return list;
}
与清单更换
public List<Tender> Get()
{
TndCustomerTendersCollection collection = new TndCustomerTendersCollection();
collection.Query
.Select
(
collection.Query.CustomerTenderID,
collection.Query.CustomerTenderID,
collection.Query.CustomerTenderCode,
collection.Query.CustomerTenderName,
collection.Query.StartDate,
collection.Query.DueDate,
collection.Query.CompleteDate,
collection.Query.DateCreated,
collection.Query.LastDateModified
)
.Where
(
collection.Query.IsActive.Equal(true)
);
// HOW DO CONVERT THAT TO THAT LIST
List<Tender> list = new List<Tender>();
foreach (TndCustomerTenders item in collection)
{
list.Add(item);
}
return list;
}
TndCustomerTenders延伸投标吗?因为在第二个例子中,你有一个Tender对象列表,而不是TndCustomerTenders对象。要转换上面的内容,可以使用List –
列表不是List ? –
您的foreach循环不应该是:foreach(收集中的投标项)? –