这必须是如此简单...在T-SQL中,我需要一秒钟。
在获得重复标志之前……我一直在尝试发布一些类似的问题,并且已经进行了数小时的研究,修改了涉及JTokens的各种回复,更改为IEnumerable,仅反序列化了一个字段,仅举几例。我不断收到错误消息,例如:
xamarin无法隐式转换类型 从'System.Collections.Generic.List到'System.Colletions.List
我已经将xml文件反序列化为这样的列表:
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;
Stream stream = assembly.GetManifestResourceStream("papapp.WineCatInfo.xml");
List<WineCategoryInfo> winecategoryinfos;
using (var reader = new StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<WineCategoryInfo>));
winecategoryinfos = (List<WineCategoryInfo>)serializer.Deserialize(reader);
}
#endregion
return winecategoryinfos;
它填充的列表的定义如下:
public class WineCategoryInfo
{
public string WineTypeNo { get; set; }
public string WineFamily { get; set; }
public string MainStyle { get; set; }
public string StyleType { get; set; }
public string LengthCharacteristic { get; set; }
public string RegionCommonAppelation { get; set; }
}
我希望对反序列化日期进行查询,以将上述列表中一个特定字段的所有值放入第二个列表中,其定义如下:
public class WineFamilies
{
public string WineFamily { get; set; }
}
有人可以向我解释如何实现这一目标吗?
非常感谢。
答案 0 :(得分:1)
使用LINQ
using System.Linq;
var family = (from x in winecategoryinfos select x.WineFamily).ToList<string>();
或消除重复
var family = (from x in winecategoryinfos select x.WineFamily).Distinct().ToList<string>();
如果您想使用WineFamilies类而不是字符串,请尝试
var family = (from x in winecategoryinfos select new WineFamilies() { WineFamily = x.WineFamily }).ToList();