You need using Except twice:
var list1 = new List<int> { 1, 2, 3, 4, 5};
var list2 = new List<int> { 3, 4, 5, 6, 7 };
var list3 = list1.Except(list2); //list3 contains only 1, 2
var list4 = list2.Except(list1); //list4 contains only 6, 7
var resultList = list3.Concat(list4).ToList(); //resultList contains 1, 2, 6, 7
For Example Given Below :-
string PId = "26949323-DB72-4E87-A1EB-2BB4350BD021";
Guid PrtyId;
Guid.TryParse(PId, out PrtyId);
List<BO.BuyerItemDispatch> SaleList = BuyerItemDispatchManager.GetAll().Where(t => t.SId == PrtyId && t.ItemNo == "D-D5-20").ToList();
if (SaleList.Count > 0)
{
string[] salevalue = SaleList[0].Extra1.Split(','); // sale value
List<string> saleValues = salevalue.ToList();
List<BO.PartyBooking> getReturnParty = PartyBookingManager.GetAll().Where(t => t.Extra1 == PrtyId.ToString()).ToList();
if (getReturnParty.Count > 0)
{
List<BO.PartyReturn> SaleReturnList = PartyReturnManager.GetAll().Where(t => t.SId == getReturnParty[0].Id && t.ItemNo == "D-D5-20").ToList();
if (SaleReturnList.Count > 0)
{
foreach (var item in SaleReturnList)
{
#region Range Collect Start no between end no
int sn = 0;
int en = 0;
int.TryParse(item.Size, out sn);
int.TryParse(item.NetQty, out en);
for (int i = sn; i <= en; i++)
{
ReturnValue += i + ",";
}
returnsalevalue = ReturnValue.Split(','); // return value
#endregion
}
List<string> returnValues = returnsalevalue.ToList();
List<string> finalResult = saleValues.Except(returnValues).ToList(); // Total Sale Value (Unsold)
foreach (string s in finalResult)
{
lblReturnvalue.Text += s + ", <b/>";
}
}
}
}
List<int> list1 = new List<int>();
List<int> list2 = new List<int>();
List<int> listDifference = new List<int>();
foreach (var item1 in list1)
{
foreach (var item2 in list2)
{
if (item1 != item2)
listDifference.Add(item1);
}
}
No comments :
Post a Comment