C# 函数param中的C列表
我是C语言的新手。我想把一个列表作为参数,并从第一个列表中获取的数据返回另一个列表C# 函数param中的C列表,c#,list,C#,List,我是C语言的新手。我想把一个列表作为参数,并从第一个列表中获取的数据返回另一个列表 private List<DestinationGenericMapProps> ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas) { var result = new List<DestinationGenericMapProps>(datas); return result;
private List<DestinationGenericMapProps> ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas)
{
var result = new List<DestinationGenericMapProps>(datas);
return result;
}
我得到这个错误:
错误241 System.Collections.Generic.List.Listint的最佳重载方法匹配具有一些无效参数
我知道这可能是很基本的,但我对C语言还不太熟悉,所以很难做到这一点。谢谢你的帮助。列表不是列表
除非从DestinationGenericMapProps派生出精品Web服务,否则这将不起作用
基本上,有一个ListIEnumerable构造函数,但T必须相同
将返回类型更改为List并更改新语句:
private List<BoutiqueInWebService> ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas)
{
var result = new List<BoutiqueInWebService>(datas);
return result;
}
列表不是一个列表
除非从DestinationGenericMapProps派生出精品Web服务,否则这将不起作用
基本上,有一个ListIEnumerable构造函数,但T必须相同
将返回类型更改为List并更改新语句:
private List<BoutiqueInWebService> ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas)
{
var result = new List<BoutiqueInWebService>(datas);
return result;
}
出现此错误的原因是,您正试图使用不同类型的Web服务列表中的对象填充一个类型为DestinationGenericMapProps的列表,该列表是不安全的
只有当BouityInWebService从DestinationGenericMapProps继承时,才能执行此操作。您之所以会收到错误,是因为您试图用不同类型BouityInWebService列表中的对象填充一个类型DestinationGenericMapProps的列表,而该列表是不安全的
仅当BouiteInWebService从DestinationGenericMapProps继承时,才能执行此操作。您的方法返回类型是DestinationGenericMapProps列表,但您正在尝试创建作为数据的BouiteInWebService列表 您可以这样做以匹配您的退货类型:
private List<DestinationGenericMapProps>
ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas)
{
return (from d in datas
select new DestinationGenericMapProps()
{
// map properties here
Prop1 = d.SomePropInData
}).ToList();
}
您的方法返回类型是DestinationGenericApprovs的列表,但您正在尝试创建作为数据的Web服务列表 您可以这样做以匹配您的退货类型:
private List<DestinationGenericMapProps>
ConstructDestinationMapPropsList(List<BoutiqueInWebService> datas)
{
return (from d in datas
select new DestinationGenericMapProps()
{
// map properties here
Prop1 = d.SomePropInData
}).ToList();
}
C支持函数重载,这意味着一个类可以有多个同名函数,只要参数不同。编译器通过比较参数的类型来决定调用哪个重载。这也适用于构造函数 List类的构造函数有三个重载:
List<T>()
List<T>(IEnumerable<T>)
List<T>(int)
C支持函数重载,这意味着一个类可以有多个同名函数,只要参数不同。编译器通过比较参数的类型来决定调用哪个重载。这也适用于构造函数 List类的构造函数有三个重载:
List<T>()
List<T>(IEnumerable<T>)
List<T>(int)
FiniteInWebService和DestinationGenericMapProps是否以任何方式相关?您可以使用Select LINQ扩展方法从案例中不相关的FiniteInWebService类型列表生成案例中另一类型DestinationGenericMapProps的列表。类似于datas.selectbouting=>DestinationGenericMapProps.fromboutinefinite.ToList.boutineInWebService和DestinationGenericMapProps是否以任何方式相关?您可以使用Select LINQ扩展方法从中的非相关类型boutineInWebService列表生成另一类型DestinationGenericMapProps的列表你的案子。类似于datas.selectboutine=>DestinationGenericMapProps.fromboutineboutine.ToList。
List<DestinationGenericMapProps>(IEnumerable<BoutiqueInWebService>)
var result = datas.Cast<DestinationGenericMapProps>().ToList()
var result = datas.Select(o => new DestinationGenericMapProps() { PropA = o.PropA, PropB = o.PropB /* etc */}).ToList();