我想知道一种有效的方法来从 C# 中的字符串数组中删除重复项。
例如,
string[] a = { "abc", "xyz","abc", "def", "ghi", "asdf", "ghi","xd", "abc" };
会变成,
string[] a = { "abc", "xyz","def", "ghi", "asdf", "xd" };
删除重复条目后如何填补空白?
有没有办法在不使用额外的数组来存储元素的情况下做到这一点?
我使用的方法:
1) Sorted the array
2) Replaced the duplicate entries with null
3) Copied NOT null string to a new array.
但正在寻找一种优化的方法来完成同样的事情。
编辑:我正在使用 .NET 2.0 和 VS 2005