我有一个实体的
IEnumerable<Entityclass>
,其中包含一个 string
和一个 int
成员。我需要将它转换为一个 KeyValuePair<string, double>
数组,反之亦然。但是转换时出现了强制转换错误。[DataContract]
public class Entityclass
{
[DataMember]
public string text{ get; set; }
[DataMember]
public int textcount{ get; set; }
}
我有一个 IEnumerable<Entityclass>
如何将
IEnumerable<Entityclass>
转换为KeyvaluePair<string, double>[]
数组?如何将
KeyvaluePair<string, double>[]
数组转换为KeyvaluePair<string, int>[]
数组?如何将
KeyvaluePair<string, double>
转换回IEnumerable
?
我已尝试:
topics 是 IEnumerable<Entityclass>;
topics.Cast<KeyValuePair<string, double>>().ToArray();
报错,无法转换