Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法强制转换类型为';CRUD_XML_MVC.Models.Billing';输入';System.Collections.Generic.IEnumerable_C#_.net_Asp.net Mvc 4 - Fatal编程技术网

C# 无法强制转换类型为';CRUD_XML_MVC.Models.Billing';输入';System.Collections.Generic.IEnumerable

C# 无法强制转换类型为';CRUD_XML_MVC.Models.Billing';输入';System.Collections.Generic.IEnumerable,c#,.net,asp.net-mvc-4,C#,.net,Asp.net Mvc 4,在我的MVC4应用程序中,我使用以下代码: Billing WCFBill = new Billing(); WCFBill.ID = XRec.ID; WCFBill.Customer = XRec.Customer; WCFBill.Date = XRec.Date; WCFBill.Description = XRec.Description; WCFBill.Type = XRec.Type; WCFBill.Hours = XRec.Hours

在我的MVC4应用程序中,我使用以下代码:

   Billing WCFBill = new Billing();
   WCFBill.ID = XRec.ID;
   WCFBill.Customer = XRec.Customer;
   WCFBill.Date = XRec.Date;
   WCFBill.Description = XRec.Description;
   WCFBill.Type = XRec.Type;
   WCFBill.Hours = XRec.Hours;
>  var result = ((IEnumerable<Billing>)WCFBill).Cast<Billing>().ToList();
   List<Billing> WCFBillList = new List<Billing>();
   WCFBillList.AddRange(result);
Billing WCFBill=new Billing();
WCFBill.ID=XRec.ID;
WCFBill.Customer=XRec.Customer;
WCFBill.Date=XRec.Date;
WCFBill.Description=XRec.Description;
WCFBill.Type=XRec.Type;
WCFBill.Hours=XRec.Hours;
>var result=((IEnumerable)WCFBill.Cast().ToList();
List WCFBillList=新列表();
WCFBillList.AddRange(结果);
上面的指示行引发以下错误:

无法将类型为“CRUD\u XML\u MVC.Models.Billing”的对象强制转换为类型为“System.Collections.Generic.IEnumerable`1[CRUD\u XML\u MVC.Models.Billing]”


首先,这告诉我们,
WCFBill
属于
Billing

Billing WCFBill = new Billing();
然后这一行(相关部分被剪掉)表示您正试图将
账单
对象转换为键入
IEnumerable
,这是不可能的:

(IEnumerable<Billing>)WCFBill
(IEnumerable)WCFBill

WCFBill
计费的单个实例,您正在尝试将其转换为集合

更换最后3行:

var result = ((IEnumerable<Billing>)WCFBill).Cast<Billing>().ToList();
List<Billing> WCFBillList = new List<Billing>();
WCFBillList.AddRange(result);
var result=((IEnumerable)WCFBill.Cast().ToList();
List WCFBillList=新列表();
WCFBillList.AddRange(结果);
为此:

var WCFBillList = new List<Billing> { WCFBill };
var WCFBillList=新列表{WCFBill};

您越迫切需要帮助,我们就越不迫切地想帮助您。您需要包括您尝试过的内容,我们不是调试服务。