We help IT Professionals succeed at work.

Error: Cannot implicitly convert type 'T[*,*]' to 'double[*,*]'

Last Modified: 2012-05-31
I have a procedure that sorts a 2 dimensional array. This procedure needs to return the sorted array. However I get the Cannot implicitly convert type 'T[*,*]' to 'double[*,*]'

How can I fix this?


My Code:

 double[,] dblArrABValSort = new double[22, 2];
 dblArrABValSort = SortArray(dblArrAB, 0, "ASC");

  private double[,] SortArray<T>(T[,] myArray, int sortCol, string order)  // What is <T> ?

        /// <summary>
    /// A generic routine to sort a two dimensional array of a specified type based on the specified column.
    /// </summary>
    /// <param name="array">The array to sort.</param>
    /// <param name="sortCol">The index of the column to sort.</param>
    /// <param name="order">Specify "DESC" or "DESCENDING" for a descending sort otherwise
    /// leave blank or specify "ASC" or "ASCENDING".</param>
    /// <remarks>The original array is sorted in place.</remarks>
    /// <see cref="http://stackoverflow.com/questions/232395/how-do-i-sort-a-two-dimensional-array-in-c"/>

        double[,] mySortedArray = new double[22, 2];
        int colCount = myArray.GetLength(1), rowCount = myArray.GetLength(0);
        if (sortCol >= colCount || sortCol < 0)
            throw new System.ArgumentOutOfRangeException("sortCol", "The column to sort on must be contained within the array bounds.");

        DataTable dt = new DataTable();
        // Name the columns with the second dimension index values, e.g., "0", "1", etc.
        for (int col = 0; col < colCount; col++)
            DataColumn dc = new DataColumn(col.ToString(), typeof(T));
        // Load data into the data table:
        for (int rowindex = 0; rowindex < rowCount; rowindex++)
            DataRow rowData = dt.NewRow();
            for (int col = 0; col < colCount; col++)
                rowData[col] = myArray[rowindex, col];
        // Sort by using the column index = name + an optional order:
        DataRow[] rows = dt.Select("", sortCol.ToString() + " " + order);

        for (int row = 0; row <= rows.GetUpperBound(0); row++)
            DataRow dr = rows[row];
            for (int col = 0; col < colCount; col++)
                myArray[row, col] = (T)dr[col];
        // myArray is the sorted array

        return myArray;  //Error: Cannot implicitly convert type 'T[*,*]' to 'double[*,*]'

How can I convert type 'T[*,*]' to 'double[*,*]' ?
Watch Question

AndyAinscowFreelance programmer / Consultant
This one is on us!
(Get your first solution completely free - no credit card required)
Software Engineer
This one is on us!
(Get your first solution completely free - no credit card required)


Thank you.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.