System.Collections.SortedList.RemoveAt C# (CSharp) Method

RemoveAt() public method

public RemoveAt ( int index ) : void
index int
return void
        public virtual void RemoveAt(int index)
        {
            if (index < 0 || index >= Count) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
            Contract.EndContractBlock();
            _size--;
            if (index < _size)
            {
                Array.Copy(_keys, index + 1, _keys, index, _size - index);
                Array.Copy(_values, index + 1, _values, index, _size - index);
            }
            _keys[_size] = null;
            _values[_size] = null;
            _version++;
        }

Usage Example

コード例 #1
0
ファイル: Interpolator.cs プロジェクト: timdetering/Endogine
        public double[,] CalcCachedInterpolationInfo(double a_dTime, SortedList a_sorted)
        {
            double[,] aReturn = new double[,]{{1}};

            int nIndex = 0;
            //			if (a_sorted.ContainsKey(a_dTime))
            nIndex = a_sorted.IndexOfKey(a_dTime);
            if (nIndex >= 0)
            {
                return new double[,]{{(double)a_sorted.GetByIndex(nIndex)}};
            }
            else
            {
                a_sorted.Add(a_dTime, -4711);
                nIndex = a_sorted.IndexOfKey(a_dTime);
                a_sorted.RemoveAt(nIndex);
            }

            //nIndex is meant to represent the next index after a_dTime.
            //If a_dTime is the same as a key, nIndex should be that key's index - 1

            if (nIndex <= 0)
                return new double[,]{{(double)a_sorted.GetByIndex(0)}};

            if (nIndex >= a_sorted.Count)
                return new double[,]{{(double)a_sorted.GetByIndex(a_sorted.Count-1)}};

            double dTimeAtIndexBefore = (double)a_sorted.GetKey(nIndex-1);
            double dTimeAtIndexAfter = (double)a_sorted.GetKey(nIndex);

            if (a_dTime == dTimeAtIndexAfter)
            {
                /*    if (nPos < nCnt) then nPos = nPos+1
            fTimePosBefore = a_paList.getPropAt(nPos-1)
            fTimePosAfter = a_paList.getPropAt(nPos)*/
            }

            double dVal1 = 0;
            double dVal2 = (double)a_sorted.GetValueList()[nIndex-1];
            double dVal3 = (double)a_sorted.GetValueList()[nIndex];
            double dVal4 = 0;
            //TODO: support commands in the list!
            //if (ilk(mvVal2) = #List) then mvVal2 = mvVal3
            //if (ilk(mvVal3) = #List) then mvVal3 = mvVal2

            if (nIndex == 1)
                dVal1 = dVal2;
            else
                dVal1 = (double)a_sorted.GetValueList()[nIndex-2];
            //if (ilk(mvVal1) = #List) then mvVal1 = mvVal2

            if (nIndex == a_sorted.Count-1)
                dVal4 = dVal3;
            else
                dVal4 = (double)a_sorted.GetValueList()[nIndex+1];
            //TODO if (ilk(mvVal4) = #List) then mvVal4 = mvVal3

            aReturn = new double[,] {{dVal1, 0}, {dVal2, dTimeAtIndexBefore}, {dVal3, dTimeAtIndexAfter}, {dVal4,0}};
            return aReturn;
        }
All Usage Examples Of System.Collections.SortedList::RemoveAt