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日 21: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日 21: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;