gpt4 book ai didi

c# - 我将如何使用 Linq 方法语法获得独特的结果

转载 作者:太空宇宙 更新时间:2023-11-03 18:42:16 24 4
gpt4 key购买 nike

我在表中有以下数据:

例如数据

0, 'Ford'    1, 'Toyota, Toyota'  2, 'BMW'  3, 'Porsche, Porsche'  4, 'BMW'  

I need to place this data in the following type List<Tuple<int, string>> carList so that the results within my list would appear as follows:

0, 'Ford'    1, 'Toyota'  2, 'BMW'  3, 'Porsche'  4, 'BMW'  

using the following pseudo code:

while (SQLiteDataReader.Read())  
{
carList.Add
(
new Tuple<int, string> (
SQLiteDataReader.GetInt32(0) ,
SQLiteDataReader.GetString(1).[Some extension method to produce unique items]
);
)
}

请注意,当有重复项(Toyota、Porsche)时,重复的名称将始终相同。也就是说,您不会得到像“Toyota, Ford”之类的东西。

是否有一些扩展方法可以删除重复部分?

最佳答案

这应该可以解决问题:

SQLiteDataReader.GetString(1).Split(',').First().Trim()

关于c# - 我将如何使用 Linq 方法语法获得独特的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7589812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com