3
我有一個包傳遞應用程序,並且在我的代碼中收到錯誤下面:錯誤「無法將類型'System.Int32'的對象轉換爲鍵入'System.Collections.Generic.List`1 [System.Int32]'」
public class DeliveryDriver
{
public List<int> DriverID { get; set; }
public List<string> DriverName { get; set; }
}
var IDeliveryDriver = new List<DeliveryDriver>();
foreach (DataRow dr in dsDriverID.Tables[0].Rows)
{
IDeliveryDriver.Add(new DeliveryDriver
{
DriverID = (List<int>)dr["DriverId"],
DriverName = (List<string>)dr["DriverName"]
});
}
在IDeliveryDriver.Add
線上發生錯誤並且它進入一個catch塊。錯誤是:
無法轉換類型 'System.Int32' 的目的是鍵入 'System.Collections.Generic.List`1 [System.Int32]'
什麼原因造成的錯誤?
5不是一個列表。這是一個5. –
是一個DeliveryDriver的DriverID真的應該是一個'List'?就像錯誤說的那樣,你不能將dr [「DriverId」]作爲'List '來投放。 –
MikeSmithDev