Jagged Arrays
Jagged arrays is a multidimentional array in VB.NET. Jagged arrays are also known as array of arrays where the the length of each array can be different. For instance, the first array can have 8 items, the second array can have 6 items and the third array can have 3 items and so on. Jagged array can be useful in many circumstances where the number of items differs for each arrays such as in recipes. For example, Food A is made up of 8 ingredients, Food B is made up of 6 ingredients while Food C is made up of 3 ingredients etc.
The codes below illustrates the application of jagged arrays.
Dim Food(2)() ' declare 3 types of foods
Food(0) = New String() {"Salt","Egg","Butter") 'first food is made up of the 3 ingredients
Food(1) = New String() {"Egg","Sugar","Butter","Flour","Banana","Water"}
Food(2) = New String() {"Carrot","Cabbage","Mayonaise","Lettuce"}
'if we were to output the selected item below
Msgbox(Food(1)(2)) 'the result will be "Butter"
Hope this helps you understand the use of jagged arrays in VB.NET better.
Subscribe to:
Post Comments (Atom)

0 comments
Post a Comment