MSDN > 論壇首頁 > .NET Base Class Library > Hashtable.Values.CopyTo()
發問發問
 

已答覆Hashtable.Values.CopyTo()

  • 2007年2月6日 上午 11:03HarryBedi 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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

解答

  • 2007年7月31日 下午 09:22Inbar Gazit版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    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.

     

所有回覆

  • 2007年7月31日 下午 09:22Inbar Gazit版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆

    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.

     

  • 2007年8月1日 下午 12:57Thomas Danecker 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    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;