Posted by: Sourav | September 15, 2016

List collection class in vb,vb teacher Sourav,Kolkata 09748184075


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

Sub Main()
Dim customer1 As customer = New customer() With {.idmanipulate = 1, .namemanipulate = “Sourav”, .salarymanipulate = 3000}
Dim customer2 As customer = New customer() With {.idmanipulate = 2, .namemanipulate = “Sougata”, .salarymanipulate = 5000}
Dim customer3 As customer = New customer() With {.idmanipulate = 3, .namemanipulate = “Subrata”, .salarymanipulate = 7000}
Dim listCustomers As New List(Of customer)(2)
listCustomers.Add(customer1)
listCustomers.Add(customer2)
listCustomers.Add(customer3)
‘Dim c As customer = listCustomers(0)
‘Console.WriteLine(“ID= {0}, Name={1} ,Salary={2}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate)
‘For Each c As customer In listCustomers
‘    Console.WriteLine(“ID= {0}, Name={1} ,Salary={2}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate)
‘Next
Dim i As Integer
For i = 0 To listCustomers.Count – 1
Console.WriteLine(“ID= {0}, Name={1} ,Salary={2}”, listCustomers(i).idmanipulate, listCustomers(i).namemanipulate, listCustomers(i).salarymanipulate)

Next

Dim sc As savingscustomer = New savingscustomer
‘listCustomers.Add(sc)
‘ listCustomers.Add(100)
‘list generic clollection class is strongly typed ,which means now I can not insert
‘anything other than customer type in the list
‘Now let’s try to insert an object at a particular location
listCustomers.Insert(0, customer3)
For i = 0 To listCustomers.Count – 1
Console.WriteLine(“ID= {0}, Name={1} ,Salary={2}”, listCustomers(i).idmanipulate, listCustomers(i).namemanipulate, listCustomers(i).salarymanipulate)

Next
‘ok let’s try to find the index of a particular object
Console.WriteLine(“the index of customer3 object is {0}”, listCustomers.IndexOf(customer3))
Console.WriteLine(“the second index of customer3 object is {0}”, listCustomers.IndexOf(customer3, 1))
Console.WriteLine(“the second index of customer3 object is {0}”, listCustomers.IndexOf(customer3, 1, 3))
Console.ReadLine()

End Sub

End Module
Public Class customer
Public id As Integer
Private name As String
Private salary As Integer
Public Property idmanipulate As Integer
Set(ByVal id As Integer)
Me.id = id
End Set
Get
Return Me.id

End Get
End Property
Public Property namemanipulate As String
Set(ByVal name As String)
Me.name = name
End Set
Get
Return Me.name

End Get
End Property
Public Property salarymanipulate As Integer
Set(ByVal salary As Integer)
Me.salary = salary
End Set
Get
Return Me.salary

End Get
End Property

End Class
Public Class savingscustomer
Inherits customer

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: