<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: manoj1808</title>
    <description>The latest articles on DEV Community by manoj1808 (@manoj1808).</description>
    <link>https://dev.to/manoj1808</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F631271%2Fea6733b2-93bb-4b64-bc98-0cfefb55c0f3.png</url>
      <title>DEV Community: manoj1808</title>
      <link>https://dev.to/manoj1808</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manoj1808"/>
    <language>en</language>
    <item>
      <title>Resizing of arrays in C</title>
      <dc:creator>manoj1808</dc:creator>
      <pubDate>Fri, 14 May 2021 15:00:32 +0000</pubDate>
      <link>https://dev.to/manoj1808/resizing-of-arrays-in-c-5fc2</link>
      <guid>https://dev.to/manoj1808/resizing-of-arrays-in-c-5fc2</guid>
      <description>&lt;p&gt;Array.Resize(T[], Int32) Method is used to resize the number of elements present in the array. Or in other words, this method is used to change the number of elements of a one-dimensional array to the specified new size. It resizes the only 1-D array, not multidimensional array.&lt;/p&gt;

&lt;p&gt;Syntax:&lt;/p&gt;

&lt;p&gt;public static void Resize (ref T[] array, int newSize);&lt;br&gt;
Parameters:&lt;/p&gt;

&lt;p&gt;array: It is a one-dimensional, zero-based array to resize, or null to create a new array with the specified size.&lt;br&gt;
newsize: It is the size of the new array.&lt;/p&gt;

&lt;p&gt;Exception:If the value of nsize is less than zero, then this method will give ArgumentOutOfRangeException.&lt;/p&gt;

&lt;p&gt;Note: This method is an O(n) operation, where n is new size.&lt;/p&gt;

&lt;p&gt;Below given are some examples to understand the implementation in a better way:&lt;/p&gt;

&lt;p&gt;Example 1:&lt;/p&gt;

&lt;p&gt;// C# program to resize the &lt;br&gt;
// elements of the 1-D array &lt;/p&gt;

&lt;p&gt;using System; &lt;/p&gt;

&lt;p&gt;public class GFG { &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Main method 

static public void Main() 

{ 



    // create and initialize array 

    string[] myarray = {"C#", "Java", "C++", "Python", 

                         "HTML", "CSS", "JavaScript"}; 



    // Display original array before Resize 

    Console.WriteLine("Original Array:"); 



    foreach(string i in myarray) 

    { 

        Console.WriteLine(i); 

    } 



    int len = myarray.Length; 

    Console.WriteLine("Length of myarray: "+len); 

    Console.WriteLine(); 



    // Resize the element of myarray and  

    // create a new array. Here new array 

    // is smaller than the original array  

    // so, elements are copied from the  

    // myarray to the new array until the 

    // new one is filled. The rest of the 

    // elements in the old array are ignored 

    Array.Resize(ref myarray, len - 3); 



    Console.WriteLine("New array is less than myarray:"); 



    foreach(string j in myarray) 

    { 

        Console.WriteLine(j); 

    } 



} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;} &lt;br&gt;
Output:&lt;br&gt;
Original Array:&lt;br&gt;
C#&lt;br&gt;
Java&lt;br&gt;
C++&lt;br&gt;
Python&lt;br&gt;
HTML&lt;br&gt;
CSS&lt;br&gt;
JavaScript&lt;br&gt;
Length of myarray: 7&lt;/p&gt;

&lt;p&gt;New array is less than myarray:&lt;br&gt;
C#&lt;br&gt;
Java&lt;br&gt;
C++&lt;br&gt;
Python&lt;br&gt;
Example 2:&lt;/p&gt;

&lt;p&gt;// C# program to resize the&lt;br&gt;&lt;br&gt;
// elements of the 1-D array &lt;/p&gt;

&lt;p&gt;using System; &lt;/p&gt;

&lt;p&gt;public class GFG { &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Main method 

static public void Main() 

{ 



    // create and initialize array 

    string[] myarray = {"C#", "C++", "Ruby",  

                     "Java", "PHP", "Perl"}; 



    // Display original string before Resize 

    Console.WriteLine("Original Array:"); 



    foreach(string i in myarray) 

    { 

        Console.WriteLine(i); 

    } 



    // Length of old array 

    int len = myarray.Length; 

    Console.WriteLine("Length of myarray: "+len); 

    Console.WriteLine(); 



    // Resize the element of myarray  

    // and create a new array 

    // Here new array is greater than 

    // original array so, all the element  

    // from myarray is copied to new array 

    // and remaining will be null 

    Array.Resize(ref myarray, 10); 



    Console.WriteLine("New array is greater than myarray:"); 



    foreach(string j in myarray) 

    { 

        Console.WriteLine(j); 

    } 



    // Length of new array 

    int len1 = myarray.Length; 

    Console.WriteLine("Length of New Array: "+len1); 



} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;} &lt;br&gt;
Output:&lt;br&gt;
Original Array:&lt;br&gt;
C#&lt;br&gt;
C++&lt;br&gt;
Ruby&lt;br&gt;
Java&lt;br&gt;
PHP&lt;br&gt;
Perl&lt;br&gt;
Length of myarray: 6&lt;/p&gt;

&lt;p&gt;New array is greater than myarray:&lt;br&gt;
C#&lt;br&gt;
C++&lt;br&gt;
Ruby&lt;br&gt;
Java&lt;br&gt;
PHP&lt;br&gt;
Perl&lt;/p&gt;

&lt;p&gt;Length of New Array: 10&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
