<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Expand/Increase size of an array</Title>
      <Shortcut>Expand/Increasesizeofanarray</Shortcut>
      <Description>Expand/Increase size of an array [C#]</Description>
      <Author>Jan Zieschang</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=cacfd5c3-04ee-4d9e-bde8-322765dd74f9</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[		/// <summary>
		/// Expands the array by the given size.
		/// </summary>
		/// <param name="array">the source array. <see langword="null"/> can be null. All values will be copied to the new array.</param>
		/// <param name="size">Increment size of the new array</param>
		/// <param name="arrayItemType">types of the new array</param>
		/// <returns></returns>
		/// <exception cref="ArgumentNullException">if arrayItemType parameter is null.</exception>
		/// <exception cref="ArgumentOutOfRangeException">if size parameter is less or equal to zero</exception>
		/// <exception cref="FormatException">if type of source array is not convertable to arrayItemType</exception>
		public static Array ExpandArray(Array array, int size, Type arrayItemType)
		{
			if(arrayItemType == null)
				throw new ArgumentNullException("arrayItemType");
			if(size <= 0)
				throw new ArgumentOutOfRangeException("size", size, "Size must be greater then 0!");
			Array me = Array.CreateInstance(arrayItemType, array == null ? size : array.Length + size);
			if(array != null && array.Length > 0)
			{
				for(int i = 0; i < array.Length; i++)
				{
					object val = array.GetValue(i);
					me.SetValue(Convert.ChangeType(val, arrayItemType) , i);
				}
			}
			return me;
		}
]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>