Performing insertion sort in C# This is my code in C# for performing insertion sort:

static int[] performInsertionSort(int[] inputarray)
{
    for (int i = 0; i &lt; inputarray.Length-1; i++)
    {
        int j = i+1;

        while (j&gt;0)
        {
            if (inputarray[j-1] &gt; inputarray[j])
            {
                int temp = inputarray[j-1];
                inputarray[j - 1] = inputarray[j];
                inputarray[j] = temp;

            }
            j--;
        }
    }
    return inputarray;
}


Is there a way to optimize this code? Can I make further changes to it?
Your sorting logic is dependent upon the specific type.

"Separate your data representation from logic." you must take advantage of the generic to reuse the same component to sort any kind of object. In case of class you can specify comparer to sort the values.    

Naming convention should be followed. i and j does not make sense and in c# standard method naming convetion should Pascal case , should not start with lowercase.

Rest logic looks good. 

public static T[] PerformInsertionSort&lt;T&gt;(T[] inputarray, Comparer&lt;T&gt; comparer=null)
    {
        var equalityComparer = comparer ?? Comparer&lt;T&gt;.Default;
        for (var counter = 0; counter &lt; inputarray.Length - 1; counter++)
        {
            var index = counter + 1;
            while (index &gt; 0)
            {
                if(equalityComparer.Compare(inputarray[index - 1],inputarray[index])&gt;0)
                {
                    var temp = inputarray[index - 1];
                    inputarray[index - 1] = inputarray[index];
                    inputarray[index] = temp;
                }
                index--;
            }
        }
        return inputarray;
    }