using System.Collections.Generic;
using System.Diagnostics;
public int Id { get; set; }
public string Name { get; set; }
public override bool Equals(object obj)
if (obj is CompanyDTO other)
return Id == other.Id && Name == other.Name;
public override int GetHashCode()
return HashCode.Combine(Id, Name);
private static List<CompanyDTO> Sourcels;
private static List<CompanyDTO> Destinationls;
private static HashSet<CompanyDTO> SourceSet;
private static HashSet<CompanyDTO> DestinationSet;
private static int n_data = 200000;
private static int n_select = 190000;
public static void Main(string[] args)
Sourcels = new List<CompanyDTO>();
Destinationls = new List<CompanyDTO>();
SourceSet = new HashSet<CompanyDTO>(Sourcels);
DestinationSet = new HashSet<CompanyDTO>();
List<CompanyDTO> SelectItem = SelectNItem(n_select);
Stopwatch stopwatch = new Stopwatch();
MoveSourceList2DestinationList(SelectItem);
Console.WriteLine($"Process_List Time: {stopwatch.ElapsedMilliseconds} ms");
Console.WriteLine($"Source List: {Sourcels.Count}");
Console.WriteLine($"Dest List: {Destinationls.Count}");
MoveSourceSet2DestinationSet(SelectItem);
Console.WriteLine($"Process Set Time: {stopwatch.ElapsedMilliseconds} ms");
Console.WriteLine($"Source Set: {SourceSet.Count}");
Console.WriteLine($"Dest Set: {DestinationSet.Count}");
public static void InitializeSourceList()
for (int i = 1; i <= n_data; i++)
Sourcels.Add(new CompanyDTO { Id = i, Name = $"Company {i}" });
public static List<CompanyDTO> SelectNItem(int pSelect)
return Sourcels.Take(pSelect).ToList();
public static void MoveSourceList2DestinationList(List<CompanyDTO> pSelectedItem)
foreach (var item in pSelectedItem)
public static void MoveSourceSet2DestinationSet(List<CompanyDTO> pSelectedItem)
foreach (var item in pSelectedItem)
DestinationSet.Add(item);