using System; using System.Linq; using System.Collections.Generic;
public static void Main()
var ValidationIdToInsert = new List<Int16>(); var ValidationIdToDelete = new List<Int16>(); var ValidationIdToUpdateWith = new List<Int16>();
var ValidationIdUpdateNew = new List<Int16>(); var intersect = new List<Int16>(); var temp = new List<Int16>();
List<Int16> Current = new List<Int16>{6,12,13,14,15};
List<Int16> New = new List<Int16>{6,12,13,14,15};
intersect = Current.Intersect(New).ToList();
string Newstr = string.Empty; string Currentstr = string.Empty;
if(Current != null && New != null && Current.Count > New.Count)
Console.WriteLine("Condition - 1");
if(intersect != null && intersect.Count > 0 && New.Count > intersect.Count)
Console.WriteLine("Condition - 1.1");
Current = Current.Except(intersect).ToList();
New = New.Except(intersect).ToList();
temp.RemoveRange(0, New.Count);
ValidationIdToUpdateWith = Current.Except(temp).ToList();
ValidationIdUpdateNew.AddRange(New);
ValidationIdToDelete.AddRange(temp);
else if(intersect != null && intersect.Count > 0 && New.Count <= intersect.Count)
Console.WriteLine("Condition- 1.2");
Current = Current.Except(intersect).ToList();
ValidationIdToDelete.AddRange(Current);
else if(intersect != null && intersect.Count <= 0)
Console.WriteLine("Condition- 1.3");
temp.RemoveRange(0, New.Count);
ValidationIdToUpdateWith = Current.Except(temp).ToList();
ValidationIdUpdateNew.AddRange(New);
ValidationIdToDelete.AddRange(temp);
else if (Current.Count < New.Count)
Console.WriteLine("Condition- 2");
if(Current != null && Current.Count <= 0)
Console.WriteLine("Condition- 2.1");
ValidationIdToInsert.AddRange(New);
else if(intersect != null && intersect.Count > 0 && New.Count > intersect.Count)
Console.WriteLine("Condition- 2.2");
Current = Current.Except(intersect).ToList();
New = New.Except(intersect).ToList();
temp.RemoveRange(0, Current.Count);
ValidationIdUpdateNew = New.Except(temp).ToList();
ValidationIdToUpdateWith.AddRange(Current);
ValidationIdToInsert.AddRange(temp);
else if(intersect != null && intersect.Count > 0 && New.Count <= intersect.Count)
Console.WriteLine("Condition- 2.3");
Current = Current.Except(intersect).ToList();
ValidationIdToDelete.AddRange(Current);
else if (intersect != null && Current.Count == New.Count)
Console.WriteLine("Condition- 3");
Current = Current.Except(intersect).ToList();
New = New.Except(intersect).ToList();
ValidationIdToUpdateWith.AddRange(Current);
ValidationIdUpdateNew.AddRange(New);
else if (New.Count == intersect.Count)
Console.WriteLine("Nothing to do - Condition- 4");
else if(Current != null && Current.Count == 0)
ValidationIdToInsert.AddRange(Current);
string Insert = string.Empty; string Delete = string.Empty; string Update = string.Empty; string UpdateWith = string.Empty; string CommonInBoth = string.Empty;
string NewNotInCurrentstr = string.Empty; string CurrentNotInNewstr = 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 ValidationIdToUpdateWith)
Console.WriteLine("UpdateWith List: " + Update);
foreach(var item in ValidationIdUpdateNew)
UpdateWith += item + ",";
Console.WriteLine("UpdateNew List: " + UpdateWith);