ソースコード
private static bool HasDuplicateElements<T>( this IReadOnlyList<T> self )
{
for ( var i = 0; i < self.Count - 1; i++ )
{
for ( var j = i + 1; j < self.Count; j++ )
{
if ( self[ i ].Equals( self[ j ] ) )
{
return true;
}
}
}
return false;
}
使用例
int[] array1 = { 1, 2, 3, 4, 5 };
int[] array2 = { 1, 2, 3, 2, 4 };
string[] array3 = { "apple", "banana", "apple" };
Debug.Log( HasDuplicateElements( array1 ) );
Debug.Log( HasDuplicateElements( array2 ) );
Debug.Log( HasDuplicateElements( array3 ) );