Posted by: Sourav | September 22, 2016

TrueForAll, AsReadOnly and TrimExcess method in List Collection Class in VB,Vb Teacher Sourav,Kolkata 09748184075


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

Sub Main()

Dim customer1 As customer = New customer() With {.idmanipulate = 1, .namemanipulate = “Sourav”, .salarymanipulate = 30000, .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 = 70000, .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 = 110000, .typemanipulate = “Corporate Customer”}
Dim customer6 As customer = New customer() With {.idmanipulate = 6, .namemanipulate = “Prakash”, .salarymanipulate = 150000, .typemanipulate = “Corporate Customer”}
Dim listcustomers As List(Of customer) = New List(Of customer)
listcustomers.Add(customer1)
listcustomers.Add(customer2)
listcustomers.Add(customer3)
listcustomers.Add(customer4)
listcustomers.Add(customer5)

Console.WriteLine(“all list members has salary equal or more than 5000 is {0}”, listcustomers.TrueForAll(Function(x) x.salarymanipulate >= 5000))

Dim readonlycustomers As ReadOnlyCollection(Of customer) = listcustomers.AsReadOnly()
‘Now this readonly list does not have an add method
‘readonlycustomers.add(customer6)
Console.WriteLine(“Number of items in readonlycustomers list is {0}”, readonlycustomers.Count)
Dim limitedlistcustomers As List(Of customer) = New List(Of customer)(100)
limitedlistcustomers.Add(customer1)
limitedlistcustomers.Add(customer2)
limitedlistcustomers.Add(customer3)
limitedlistcustomers.Add(customer4)
limitedlistcustomers.Add(customer5)
Console.WriteLine(“the capacity of the new list before trimming is {0}”, limitedlistcustomers.Capacity)
limitedlistcustomers.TrimExcess()
Console.WriteLine(“the capacity of the new list after trimming is {0}”, limitedlistcustomers.Capacity)
limitedlistcustomers.Add(customer6)
Console.WriteLine(“the capacity of the new list after adding an element after trimming {0}”, limitedlistcustomers.Capacity)

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: