I want to sort an array of either integers or doubles. For this i want to use one method. My problem is that I don't know how to pass an array with an unknown type as a parameter. I tried this
public static void BubbleSort<T>(T[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
for (int j = 0; j < arr.Length - 1; j++)
{
//Can't use greater than because of T
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
But now I can't use the greater than operator because the array could also be an array of strings.