How to display message using Lambda in C#

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

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var invoiceDataList = new List<InvoiceData>();

//populating some data
Enumerable
.Range(1, 10)
.ToList()
.ForEach(
i =>
invoiceDataList.Add(new InvoiceData
{
InvoiceId = i,
InvoiceNumber = i + 10,
InvoiceDate = DateTime.Now.AddDays(i),
TotalAmount = i % 2 == 0 ? 20000 + i : 1000 + i,
ReceivedAmount = i % 2 == 0 ? 1000 + i: 20000 + i
})
);

//the program
var InvoiceMasterList = new List<InvoiceMaster>();
invoiceDataList
.ToList()
.ForEach(i =>
{
if (i.ReceivedAmount > i.TotalAmount)
Console.WriteLine("You Have Entered More Amount Than Invoice Amount");
else
InvoiceMasterList.Add(new InvoiceMaster
{
InvoiceId = i.InvoiceId,
InvoiceNumber = i.InvoiceNumber,
InvoiceDate = i.InvoiceDate,
TotalAmount = i.TotalAmount,
ReceivedAmount = i.ReceivedAmount
});
});


}
}

public class InvoiceData
{
public int InvoiceId { get; set; }
public int InvoiceNumber { get; set; }
public DateTime InvoiceDate { get; set; }
public int TotalAmount { get; set; }
public int ReceivedAmount { get; set; }

}

public class InvoiceMaster
{
public int InvoiceId { get; set; }
public int InvoiceNumber { get; set; }
public DateTime InvoiceDate { get; set; }
public int TotalAmount { get; set; }
public int ReceivedAmount { get; set; }

}
}

Comments or Responses

Login to post response