You are on page 1of 10

ARRAYS, STRUCTURES AND VAL

ARRAYS IN VB.NET
• An Array is a collection of values of similar data type.
• Each array in VB.Net is an object and is inherited from the System.Array class.
• Arrays are declared as follows:
Dim <identifier>(<size of array>) As <data type>
EXAMPLE

Dim myIntegers(9) As Integer


(Or)
Dim myIntegers() As Integer
myIntegers = New Integer() {1, 2, 3, 4, 5}
THE FOR EACH LOOP

For Each <identifier> in <array or collection>


<statements or block of statements>
Next
Example:
Dim myIntegers() As Integer = New Integer() {3, 7, 2, 14, 65}
' iterating through the array
Dim i As Integer
For Each i in myIntegers
' print statement
Next
IMPORTS STATEMENT

• The imports statement is used to include a namespace into


the program.
• Namespaces act as containers to store types such as
classes, structures etc.,
STRUCTURES IN VB.NET
• A user defined data type .
• They are user-defined and provide a method for packing together data of different
types.
• Use structure keyword to declare the structure
• It is value type and store on Stack
• Cannot have explicit default constructor but can have parameterized constructors
• Cannot have destructor
• Cannot participate in inheritance
• Structure members can be private as well
Structure Customer

Private custid As Integer Class StructTest


Public Shared Sub Main()
Private name As String Dim c As New Customer(1234, "Rakesh Verma",
Private balance As Double
9000)
c.Deposit(5000)
Public Sub New(ByVal custid As Integer, ByVal name As c.ShowAccount()
String, ByVal opamt As Double) End Sub
End Class
Me.custid = custid

Me.name = name

balance = opamt

End Sub

Public Sub Deposit(ByVal amount As Double)

balance += amount

End Sub

Public Sub ShowAccount()

Console.WriteLine("Balance of {0} is {1}", name, balance)

End Sub
VAL FUNCTION

converts any string representation of a number to a number


returns double to hold the number contained in expression
val(expression)
GET STARTED WITH YOUR FIRST CONSOLE
APPLICATION
Imports System.Console
Module Module1
Sub Main()
Console.WriteLine(“Hello from visual basic 2008”)
Console.ReadLine()
End Sub
End Module

You might also like