Posted by: Sourav | September 3, 2016

Generics Example in VB,VB Teacher Sourav,Kolkata 09748184075


Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic

Module Module1

Sub Main()
Dim ans As Boolean = calculatorvb.areequal(“A”, “B”)
Console.WriteLine(ans)
ans = calculatorgen(Of String).areequalgen(“A”, “A”)
Console.WriteLine(ans)
ans = calculatorgen(Of Integer).areequalgen(10, 10)
Console.WriteLine(ans)
Console.ReadLine()

End Sub

End Module

 

Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic
Public Class calculatorgen(Of T)

Public Shared Function areequal(ByVal value1 As Object, ByVal value2 As Object) As Boolean
Return value1.Equals(value2)

End Function
Public Shared Function areequalgen(ByVal value1 As T, ByVal value2 As T) As Boolean
Return value1.Equals(value2)

End Function

End Class

 

Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic
Public Class calculatorvb
Public Shared Function areequal(ByVal value1 As Object, ByVal value2 As Object) As Boolean
Return value1.Equals(value2)

End Function
Public Shared Function areequalgen(Of T)(ByVal value1 As T, ByVal value2 As T) As Boolean
Return value1.Equals(value2)

End Function
End Class

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: