using System; using System.Linq; using System.Collections.Generic;
{ public static void Main()
{ var ValidationIdToInsert = new List<Int16>(); var ValidationIdToDelete = new List<Int16>(); var ValidationIdToUpdate = new List<Int16>(); var ValidationIdUpdateWith = new List<Int16>();
var intersect = new List<Int16>();
List<Int16> Current = new List<Int16> { 61,15,10,12};
List<Int16> New = new List<Int16> { 6,11,12,13,14,15};
var NewNotInCurrent = New.Except(Current).ToList();
var CurrentNotInNew = Current.Except(New).ToList();
intersect = New.Intersect(Current).ToList(); Console.WriteLine("intersect count: " + intersect.Count()); Console.WriteLine("NewNotInCurrent count: " + NewNotInCurrent.Count()); Console.WriteLine("CurrentNotInNew count: " + CurrentNotInNew.Count() +"\n");
if(intersect != null && intersect.Count > 0)
if(NewNotInCurrent !=null && CurrentNotInNew!=null && (intersect.Count >= NewNotInCurrent.Count) && (intersect.Count >= CurrentNotInNew.Count))
ValidationIdToInsert.AddRange(NewNotInCurrent.Except(intersect).ToList());
ValidationIdToDelete.AddRange(CurrentNotInNew.Except(intersect).ToList());
Console.WriteLine("true 1");
else if(NewNotInCurrent !=null && CurrentNotInNew!=null && (intersect.Count < NewNotInCurrent.Count) && (intersect.Count < CurrentNotInNew.Count))
Console.WriteLine("true 2");
ValidationIdToInsert.AddRange(NewNotInCurrent.Except(intersect).ToList());
ValidationIdToDelete.AddRange(CurrentNotInNew.Except(intersect).ToList());
else if(NewNotInCurrent !=null && CurrentNotInNew!=null && (intersect.Count >= NewNotInCurrent.Count) && (intersect.Count < CurrentNotInNew.Count))
Console.WriteLine("true 3");
ValidationIdToInsert.AddRange(NewNotInCurrent.Except(intersect).ToList());
ValidationIdToDelete.AddRange(CurrentNotInNew.Except(intersect).ToList());
else if(NewNotInCurrent !=null && CurrentNotInNew!=null && (intersect.Count < NewNotInCurrent.Count) && (intersect.Count >= CurrentNotInNew.Count))
Console.WriteLine("true 4");
ValidationIdToInsert.AddRange(NewNotInCurrent.Except(intersect).ToList());
ValidationIdToDelete.AddRange(CurrentNotInNew.Except(intersect).ToList());
Console.WriteLine("true 3 : Intersect is empty");
ValidationIdToInsert.AddRange(NewNotInCurrent);
ValidationIdToDelete.AddRange(CurrentNotInNew);
string Insert = string.Empty; string Delete = string.Empty; string Update = string.Empty; string UpdateWith = string.Empty; string CommonInBoth = string.Empty;
string Newstr = string.Empty; string Currentstr = string.Empty;
foreach(var item in Current)
Currentstr += item + ",";
Console.WriteLine("Current List: " + Currentstr);
Console.WriteLine("New List: " + Newstr + "\n");
foreach(var item in intersect)
CommonInBoth += item + ",";
Console.WriteLine("CommonInBoth List: " + CommonInBoth);
foreach(var item in ValidationIdToInsert)
Console.WriteLine("Insert List: " + Insert);
foreach(var item in ValidationIdToDelete)
Console.WriteLine("Delete List: " + Delete);
foreach(var item in ValidationIdToUpdate)
Console.WriteLine("Update List: " + Update);
foreach(var item in ValidationIdUpdateWith)
UpdateWith += item + ",";
Console.WriteLine("UpdateWith List: " + UpdateWith);