How to display message using Lambda in VB.net?

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 245
We can use Statement Lambda for this purpose. An workable solution is presented below

Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication1
Class Program
Private Shared Sub Main(args As String())
Dim invoiceDataList = New List(Of InvoiceData)()

'populating some data
Enumerable.Range(1, 10).ToList().ForEach(Function(i) invoiceDataList.Add(New InvoiceData() With { _
Key .InvoiceId = i, _
Key .InvoiceNumber = i + 10, _
Key .InvoiceDate = DateTime.Now.AddDays(i), _
Key .TotalAmount = If(i Mod 2 = 0, 20000 + i, 1000 + i), _
Key .ReceivedAmount = If(i Mod 2 = 0, 1000 + i, 20000 + i) _
}))

'the program
Dim InvoiceMasterList = New List(Of InvoiceMaster)()
invoiceDataList.ToList().ForEach(Function(i)
If i.ReceivedAmount > i.TotalAmount Then
Console.WriteLine("You Have Entered More Amount Than Invoice Amount")
Else
InvoiceMasterList.Add(New InvoiceMaster() With { _
Key .InvoiceId = i.InvoiceId, _
Key .InvoiceNumber = i.InvoiceNumber, _
Key .InvoiceDate = i.InvoiceDate, _
Key .TotalAmount = i.TotalAmount, _
Key .ReceivedAmount = i.ReceivedAmount _
})
End If

End Function)


End Sub
End Class

Public Class InvoiceData
Public Property InvoiceId() As Integer
Get
Return m_InvoiceId
End Get
Set
m_InvoiceId = Value
End Set
End Property
Private m_InvoiceId As Integer
Public Property InvoiceNumber() As Integer
Get
Return m_InvoiceNumber
End Get
Set
m_InvoiceNumber = Value
End Set
End Property
Private m_InvoiceNumber As Integer
Public Property InvoiceDate() As DateTime
Get
Return m_InvoiceDate
End Get
Set
m_InvoiceDate = Value
End Set
End Property
Private m_InvoiceDate As DateTime
Public Property TotalAmount() As Integer
Get
Return m_TotalAmount
End Get
Set
m_TotalAmount = Value
End Set
End Property
Private m_TotalAmount As Integer
Public Property ReceivedAmount() As Integer
Get
Return m_ReceivedAmount
End Get
Set
m_ReceivedAmount = Value
End Set
End Property
Private m_ReceivedAmount As Integer

End Class

Public Class InvoiceMaster
Public Property InvoiceId() As Integer
Get
Return m_InvoiceId
End Get
Set
m_InvoiceId = Value
End Set
End Property
Private m_InvoiceId As Integer
Public Property InvoiceNumber() As Integer
Get
Return m_InvoiceNumber
End Get
Set
m_InvoiceNumber = Value
End Set
End Property
Private m_InvoiceNumber As Integer
Public Property InvoiceDate() As DateTime
Get
Return m_InvoiceDate
End Get
Set
m_InvoiceDate = Value
End Set
End Property
Private m_InvoiceDate As DateTime
Public Property TotalAmount() As Integer
Get
Return m_TotalAmount
End Get
Set
m_TotalAmount = Value
End Set
End Property
Private m_TotalAmount As Integer
Public Property ReceivedAmount() As Integer
Get
Return m_ReceivedAmount
End Get
Set
m_ReceivedAmount = Value
End Set
End Property
Private m_ReceivedAmount As Integer

End Class
End Namespace

Comments or Responses

Login to post response