Ask a questionAsk a question
 

AnswerHashtable.Values.CopyTo()

  • Tuesday, February 06, 2007 11:03 AMHarryBedi Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi Guys,

    I am trying to convert the values in my hashtable to an array.  I am using the hashtable.values.CopyTo() function but it always breaks, it doesn't seem to matter if I change my array type.

    The data in the hashtable is a [,] and i would prefer to keep it that way, however I know that I may have to change it to a double[ ] (conincendentaly I have done that) but I still get a error on the lines it doesnt fit.

    Can someone please help.  I have pasted my code below.

    double[]meanR = new double[7];

    theMeanReturn = mean.getMeanCcyReturns(TheReturns);//theMeanReturn returned as a [,]

    double[] TheMeanReaturn = new double[];//parse theMeanReturns to a [ ]

    for (int p = 0; p < theMeanReturn.Length;p++)

    {

    TheMeanReaturn[p] = theMeanReturn[0,p];

    }

    theMeanReturns.Add(CurrencyPairsData,TheMeanReaturn);//Take it to my hashtable

    TheMeanReaturn.Length.ToString();

    theMeanReturns.Values.CopyTo(meanR,0);//This is where i attempt to convert the data from hashtable

     I

    I am either recieving errors that the array does not fit or that the combination is wrong, or Object cannot be stored in an array of this type.  I really dont know what else I shoud do?

    Thanks

    HB

Answers

  • Tuesday, July 31, 2007 9:22 PMInbar GazitModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    If the type of the elements in the Array and the size of the array matches this works just fine.

    Remember that values is an ICollection of objects. You can check the Count property to make sure you have the correct number of values and check that they are of the same correct type and this would sucsseed.

     

All Replies

  • Tuesday, July 31, 2007 9:22 PMInbar GazitModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    If the type of the elements in the Array and the size of the array matches this works just fine.

    Remember that values is an ICollection of objects. You can check the Count property to make sure you have the correct number of values and check that they are of the same correct type and this would sucsseed.

     

  • Wednesday, August 01, 2007 12:57 PMThomas Danecker Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Please change the names of your variables. There are three variables with nearly the same name! It makes it very very difficult to read your code. There's theMeanReturn, TheMeanReaturn and theMeanReturns. I think meanR should be a jagged array:

     

    Code Snippet

    double[][] meanR;