Reinventing the wheel:
First of all, you are aware that there is already a reverse method in the .NET Framework, right? Like stated: no need to reinvent the wheel. Here's link for more info on the Array.Reverse method. Unless you wanted to make your own implementation for whatever reason! :)
Variables:
I don't agree with rolfl. Whether you have long or short code, create a regular or generic method: give your variables a meaningful name. It's good practice and better for maintaining your code.
Recursion vs. Loop:
Here I do agree with rolfl. In this situation, the recursion can be replaced by the loop (not going to write that code again).
Extensions:
Since you make the effort of making a generic method, I'd take it a step further and make it an extension method. Nice for reusability and readability.
Final code:
Here's what the code looks like with all the tips I gave:
public static class Extensions
{
public static void ReverseArray<T>(this T[] array)
{
array.ReverseArray(0, array.Length - 1);
}
public static void ReverseArray<T>(this T[] array, int lower, int upper)
{
for (int i = lower, j = upper; i < j; i++, j--)
{
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
And the usage:
int[] arr = {1,2,3,4,5,6,7,8};
arr.ReverseArray();
//Result: 8 7 6 5 4 3 2 1
int[] arr = {1,2,3,4,5,6,7,8};
arr.ReverseArray(1, 3);
//Result: 1 4 3 2 5 6 7 8
Note that my tips/code might not be perfect, just trying to make you write better/cleaner code. Hope this helps! ;)
Edit:
Useful tip from rolfl to reuse the parameters instead of creating new variables in the for loop. The loop will now look like this:
for(; lower < upper; lower++, upper--)
{
var temp = array[lower];
array[lower] = array[upper];
array[upper] = temp;
}