C#查找列表中所有重复出现的元素的代码

在工作之余,将写代码过程中较好的一些代码段做个记录,如下代码内容是关于C#查找列表中所有重复出现的元素的代码,希望对码农们有一些用途。

public T[] GetDuplicates(T inputValue)
{
	List<T> duplicates = new List<T>( );
	for (int i = 0; i < this.Count; i++)
	{
		if (this[i].Equals(inputValue))
		{
			duplicates.Add(this[i]);
		}
	}
	return (duplicates.ToArray( ));
}

猜你喜欢

转载自blog.csdn.net/w_rhinoceros/article/details/89840435