从删除列表中的重复字符串(.NET 2.0!)字符串、列表中、NET

2023-09-04 10:40:13 作者:等个旧人

我有问题,找到最有效的方式,从一个字符串列表(列表)删除重复。

I'm having issues finding the most efficient way to remove duplicates from a list of strings (List).

我目前的实施是一个双foreach循环检查每个对象的实例数仅为1,否则除去第二。

My current implementation is a dual foreach loop checking the instance count of each object being only 1, otherwise removing the second.

我知道还有很多其他的问题在那里,但他们所有的最好的解决方案需要上述.NET 2.0,这是当前构建环境,我的工作(通用汽车和克莱斯勒的变化非常耐...: ))

I know there are MANY other questions out there, but they all the best solutions require above .net 2.0, which is the current build environment I'm working in. (GM and Chrysler are very resistant to changes ... :) )

这不容许任何LINQ,或HashSets限制了可能的结果。

This limits the possible results by not allowing any LINQ, or HashSets.

在code我使用的是的Visual C ++,但C#的解决方案,将工作也很不错。

The code I'm using is Visual C++, but a C# solution will work just fine as well.

谢谢!

推荐答案

这可能不是你要找的,但如果你有过这样的控制,最有效的方法是不添加他们的第一个地方...

This probably isn't what you're looking for, but if you have control over this, the most efficient way would be to not add them in the first place...

你有没有过这样的控制?如果是这样,所有你需要做的是 myList.Contains(currentItem)通话,然后添加的项目,你就设置

Do you have control over this? If so, all you'd need to do is a myList.Contains(currentItem) call before you add the item and you're set