将system.collection.objectmodel.observation转换为通用列表时出错 [英] error while converting system.collection.objectmodel.observation to generic list
本文介绍了将system.collection.objectmodel.observation转换为通用列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
void loginfn( object sender,loginCompletedEventArgs e)
{
if (e.Result!= null )
{
List< customer> c = e.Result; // 此行出现错误
< span class =code-keyword> foreach (客户c1 in c)
{
Guid id = c1.companyrefid;
}
}
else
{
MessageBox.Show( 密码不正确);
}
}
通过wcf我得到的价值
public List< customer> login(string salesmanname,string usercode)
解决方案
不要强制转换:
foreach (客户c1 e.Result)
...
1。e.Result
必须是(或必须包含缓存)对象类型:List< customer>OR
List< ParentOfCustomerClass>
2.你应该使用一个明确的演员:
<列表与LT;顾客> c =(List< customer>)e.Result;
试试这个
System.Collections.ObjectModel.ObservableCollection<顾客> temp = e.Result;
foreach ( var item in temp)
{
Guid companyrefid = item.companyrefid;
int id = item.id;
}
void loginfn(object sender, loginCompletedEventArgs e)
{
if (e.Result!= null)
{
List<customer> c = e.Result;//error arises in this line
foreach (customer c1 in c)
{
Guid id=c1.companyrefid;
}
}
else
{
MessageBox.Show("password not correct ");
}
}
through wcf i am getting values
public List<customer> login(string salesmanname, string usercode)
解决方案
Try not casting :
foreach (customer c1 in e.Result) ...
1.e.Result
must be (OR must contain as cached) an object of type:List<customer>OR
List<ParentOfCustomerClass>
2. You should use an explicit cast:
<List<customer> c = (List<customer>)e.Result;
Try this
System.Collections.ObjectModel.ObservableCollection<customer> temp = e.Result; foreach (var item in temp) { Guid companyrefid = item.companyrefid; int id = item.id; }
这篇关于将system.collection.objectmodel.observation转换为通用列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文