Example #1
0
        /// <summary>
        /// Copies the state elements to a array.
        /// </summary>
        /// <param name="array">The array to copy to. This must be capable of accepting objects of type DictionaryEntry.</param>
        /// <param name="index">The zero-based array where the copying should begin.</param>
        public virtual void CopyTo(DictionaryEntry[] array, int index)
        {
            if (null == array)
            {
                throw new ArgumentNullException("array", "RES_ExceptionNullArrayInCopyToArray");
            }
            if (1 != array.Rank)
            {
                throw new ArgumentException("RES_ExceptionInvalidArrayDimensionsInCopyToArray", "array");
            }
            if ((0 > index) || (array.GetUpperBound(0) < index) || (array.GetUpperBound(0) < (index + this.InnerHashtable.Count)))
            {
                throw new ArgumentOutOfRangeException("index", index, "RES_ExceptionOutOfBoundsIndexInCopyToArray");
            }

            try
            {
                //  attempt to copy to array
                foreach (DictionaryEntry de in this.InnerHashtable)
                {
                    array.SetValue(de, index++);
                }
            }
            catch (Exception e)
            {
                throw new InvalidCastException("RES_ExceptionInvalidCastInCopyToArray", e);
            }
        }