Posted by: Sourav | September 19, 2016

Generic List in Depth,addrange,getrange,remove,removeat,removeall,removerange,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, .typemanipulate = “Retail Customer”}
Dim customer2 As customer = New customer() With {.idmanipulate = 2, .namemanipulate = “kunal”, .salarymanipulate = 5000, .typemanipulate = “Retail Customer”}
Dim customer3 As customer = New customer() With {.idmanipulate = 3, .namemanipulate = “Subrata”, .salarymanipulate = 7000, .typemanipulate = “Retail Customer”}
Dim customer4 As customer = New customer() With {.idmanipulate = 4, .namemanipulate = “Avik”, .salarymanipulate = 9000, .typemanipulate = “Corporate Customer”}
Dim customer5 As customer = New customer() With {.idmanipulate = 5, .namemanipulate = “Manish”, .salarymanipulate = 11000, .typemanipulate = “Corporate Customer”}
Dim listcustomers As List(Of customer) = New List(Of customer)
listcustomers.Add(customer1)
listcustomers.Add(customer2)
listcustomers.Add(customer3)
Dim listcorporatecustomers As List(Of customer) = New List(Of customer)
listcorporatecustomers.Add(customer4)
listcorporatecustomers.Add(customer5)
‘let’s try the addrange method

listcustomers.AddRange(listcorporatecustomers)
For Each c As customer In listcustomers
Console.WriteLine(“ID= {0},Name={1},Salary={2},Type={3}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate, c.typemanipulate)
Console.WriteLine(“******************************************************”)

Next
Console.WriteLine()
Console.WriteLine()

‘Let’s try the getrange method
Dim customers As List(Of customer) = listcustomers.GetRange(3, 2)
For Each c As customer In customers
Console.WriteLine(“ID= {0},Name={1},Salary={2},Type={3}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate, c.typemanipulate)
Console.WriteLine(“******************************************************”)

Next
Console.WriteLine()
Console.WriteLine()
‘Ok let’s try the insertrange method
listcustomers.InsertRange(0, listcorporatecustomers)
For Each c As customer In listcustomers
Console.WriteLine(“ID= {0},Name={1},Salary={2},Type={3}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate, c.typemanipulate)
Console.WriteLine(“******************************************************”)

Next
Console.WriteLine()
Console.WriteLine()

‘Ok let’s try to remove, removeat , removeall or removerange
‘listcustomers.RemoveAt(0)
‘listcustomers.RemoveAt(1)
listcustomers.Remove(customer4)
listcustomers.Remove(customer5)

For Each c As customer In listcustomers
Console.WriteLine(“ID= {0},Name={1},Salary={2},Type={3}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate, c.typemanipulate)
Console.WriteLine(“******************************************************”)

Next

Console.WriteLine()
Console.WriteLine()

‘listcustomers.RemoveAll(Function(x) x.typemanipulate = “Corporate Customer”)
listcustomers.RemoveRange(3, 2)

For Each c As customer In listcustomers
Console.WriteLine(“ID= {0},Name={1},Salary={2},Type={3}”, c.idmanipulate, c.namemanipulate, c.salarymanipulate, c.typemanipulate)
Console.WriteLine(“******************************************************”)

Next

Console.WriteLine()
Console.WriteLine()
Console.ReadLine()
End Sub

End Module
Public Class customer
Private id As Integer
Private name As String
Private salary As Integer
Private type As String

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
Public Property typemanipulate As String
Set(ByVal type As String)
Me.type = type
End Set
Get
Return Me.type

End Get
End Property
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: