Odeslat dotazOdeslat dotaz
 

OdpovědětHashtable.Values.CopyTo()

  • 6. února 2007 11:03HarryBedi Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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

Odpovědi

  • 31. července 2007 21:22Inbar GazitModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět

    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.

     

Všechny reakce

  • 31. července 2007 21:22Inbar GazitModerátorUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     Odpovědět

    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.

     

  • 1. srpna 2007 12:57Thomas Danecker Uživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaileUživatelské medaile
     

    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;