TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Array.Resize Subroutine

Use the Array.Resize subroutine to grow and shrink an array.
Array.Resize. An array can be resized. This will either remove elements at the end if you resize it to be smaller, or add elements at the end if you resize it to be bigger. We show how the Array.Resize subroutine works in the VB.NET language.Array
Example. This program first declares an array of integers with three elements. Then, it displays the elements and also the array's total length. Next, it invokes the Array.Resize subroutine.

And: This makes the new length of the array 6. There are now three elements at the end that were not there before.

For Each, For
VB.NET program that uses Array.Resize Module Module1 Sub Main() ' Create array of three elements. Dim arr(2) As Integer arr(0) = 1 arr(1) = 2 arr(2) = 3 ' Display all elements and the length. For Each value As Integer In arr Console.Write(value) Console.Write(" ") Next Console.Write("- ") Console.WriteLine(arr.Length) ' Call Array.Resize. Array.Resize(arr, 6) ' Display all elements and the length. For Each value As Integer In arr Console.Write(value) Console.Write(" ") Next Console.Write("- ") Console.WriteLine(arr.Length) End Sub End Module Output 1 2 3 - 3 1 2 3 0 0 0 - 6
Why are the elements zero? The default value of an integer on the heap is the value zero. All the bits are set to zeros. For strings the default value will be Nothing, because no objects were allocated for the new references.Nothing
Summary. The Array.Resize subroutine is used in almost all collections in the .NET Framework. When a collection such as a List or Dictionary needs to become larger, it calls Array.Resize to resize its internal buffers, which are arrays.ListDictionary

Note: You can use Array.Resize to develop your own resizable collections as well.

© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf