Tag: convertall

链接通用列表扩展的方法

我有一个“复杂”类型的列表 – 一个具有一些字符串属性的对象。 List本身是另一个对象的属性,包含各种类型的对象,如此缩写类结构所示: Customer { public List Characteristics; . . . } Characteristic { public string CharacteristicType; public string CharacteristicValue; } 我希望能够为当前客户收集特定类型特征值的列表,我可以按如下步骤分两步完成: List interestCharacteristics = customer.Characteristics.FindAll( delegate (Characteristic interest) { return interest.CharacteristicType == “Interest”; } ); List interests = interestCharacteristics.ConvertAll( delegate (Characteristic interest) { return interest.CharacteristicValue; } ); 这很好,但似乎还有很长的路要走。 我确定我必须错过一个更简单的方法来获取这个列表,或者通过链接FindAll()和Convert()方法,或者我完全忽略的其他东西。 对于背景,我在.Net 2.0工作,所以我只限于.Net 2generics,而且特性类是外部依赖 – […]

C#List .ConvertAll效率和开销

我最近了解了List的.ConvertAll扩展。 我今天在代码中使用它几次,将我的对象的大型列表转换为其他对象的列表。 它似乎工作得很好。 但是,我不确定这与仅迭代列表和转换对象相比有多快或多快。 .ConvertAll是否会使用任何特殊的东西来加速转换过程,或者它只是一种简单的转换列表而无需设置循环的方法?

将int列表转换为字节数组

我试图使用List.ConvertAll方法并失败。 我想要做的是将List转换为byte[] 我赶紧走了这条路,但我需要找出ConvertAll方法…… List integers… internal byte[] GetBytes() { List bytes = new List(integers.Count * sizeof(byte)); foreach (Int32 integer in integers) bytes.AddRange(BitConverter.GetBytes(integer)); return bytes.ToArray(); }