Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the ReferenceEquals() method of Array class
By Nidhi Last Updated : November 13, 2024
Array.ReferenceEquals() Method in VB.Net
The ReferenceEquals() method is used to check the equality of two array references.
Syntax
Function ReferenceEquals(ByVal arr1() as object, ByVal arr2() as object) as Boolean
Parameter(s)
- Arr1: It is the specified integer array to be matched.
- Arr2: It is the specified integer array to be matched.
Return Value
It returns the True if two references of arrays are equal otherwise it will return False.
VB.Net code to demonstrate the example of Array.ReferenceEquals() method
The source code to demonstrate the ReferenceEquals() method of the Array class is given below. The given program is compiled and executed successfully.
'VB.NET program to demonstrate the ReferenceEquals()
'method of Array class.
Imports System
Module Module1
Sub Main()
Dim arr1() As Integer = {10, 20, 30, 20, 30}
Dim arr2() As Integer = {10, 20, 30, 20, 30}
If Array.ReferenceEquals(arr1, arr2) Then
Console.WriteLine("References arr1 and arr2 are equal")
Else
Console.WriteLine("References arr1 and arr2 are not equal")
End If
If Array.ReferenceEquals(arr1, arr1) Then
Console.WriteLine("References arr1 and arr1 are equal")
Else
Console.WriteLine("References arr1 and arr1 are not equal")
End If
End Sub
End Module
Output
References arr1 and arr2 are not equal
References arr1 and arr1 are equal
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program.
In the Main() function, we created two arrays arr1 and arr2. Here, we checked the equality of references arr1 and arr2 and print the appropriate messages on the console screen.
VB.Net Array Programs »