System.Collections.ArrayList.InsertRange C# (CSharp) Method

InsertRange() public method

public InsertRange ( int index, ICollection c ) : void
index int
c ICollection
return void
        public virtual void InsertRange(int index, ICollection c)
        {
            if (c == null)
                throw new ArgumentNullException(nameof(c), SR.ArgumentNull_Collection);
            if (index < 0 || index > _size) throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_Index);
            //Contract.Ensures(Count == Contract.OldValue(Count) + c.Count);
            Contract.EndContractBlock();

            int count = c.Count;
            if (count > 0)
            {
                EnsureCapacity(_size + count);
                // shift existing items
                if (index < _size)
                {
                    Array.Copy(_items, index, _items, index + count, _size - index);
                }

                Object[] itemsToInsert = new Object[count];
                c.CopyTo(itemsToInsert, 0);
                itemsToInsert.CopyTo(_items, index);
                _size += count;
                _version++;
            }
        }

Usage Example

		public static string FormatContentLocation(string contentLocation, string queryString)
		{
			var token = new char[] { '/' };

			var locationArray = contentLocation.Split(token);
			var locationArrayList = new ArrayList(locationArray);

			// Create CDN Address as array so we can insert it into url array at appropriate point
			var cdnAddressArray = new List<string> { CdnEndpoint };

			// Replace root element with http address for CDN
			if (CdnEndpoint.StartsWith("http") && ((locationArrayList[0].ToString() == "~") || (locationArrayList[0].ToString() == ".")))
			{
				locationArrayList[0] = CdnEndpoint;
			}
			else if (locationArrayList[0].ToString() == "~" || locationArrayList[0].ToString() == ".")
			{
				locationArrayList.InsertRange(1, cdnAddressArray);
			}
			else
			{
				locationArrayList.InsertRange(0, cdnAddressArray);
			}

			var newUrl = String.Join("/", locationArrayList.ToArray());
			newUrl = newUrl + queryString;

			return newUrl;
		}
All Usage Examples Of System.Collections.ArrayList::InsertRange