System.Collections.Specialized.NameValueCollection.CopyTo C# (CSharp) Method

CopyTo() public method

public CopyTo ( Array dest, int index ) : void
dest Array
index int
return void
        public void CopyTo(Array dest, int index)
        {
            if (dest == null)
            {
                throw new ArgumentNullException(nameof(dest));
            }

            if (dest.Rank != 1)
            {
                throw new ArgumentException(SR.Arg_MultiRank, nameof(dest));
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_NeedNonNegNum);
            }

            if (dest.Length - index < Count)
            {
                throw new ArgumentException(SR.Arg_InsufficientSpace);
            }

            int n = Count;
            if (_all == null)
            {
                String[] all = new String[n];
                for (int i = 0; i < n; i++)
                {
                    all[i] = Get(i);
                    dest.SetValue(all[i], i + index);
                }
                _all = all; // wait until end of loop to set _all reference in case Get throws
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    dest.SetValue(_all[i], i + index);
                }
            }
        }

Same methods

NameValueCollection::CopyTo ( System dest, int index ) : void

Usage Example

        public ResourceId(NameValueCollection parameters)
        {
            this.parameters = parameters;

            string[] values = new string[parameters.Keys.Count];
            parameters.CopyTo(values, 0);
            internalValue = string.Join(Environment.NewLine, values);
        }
All Usage Examples Of System.Collections.Specialized.NameValueCollection::CopyTo