using System.Collections.Generic;
private List<SomeDto> Data = new List<SomeDto>();
private List<SomeDto> OriginalData = new List<SomeDto>();
Console.WriteLine("Original list: ");
foreach(var dto in OriginalData)
Console.WriteLine(dto.ToString());
Console.WriteLine("Changed list: ");
Console.WriteLine(dto.ToString());
OriginalData = new List<SomeDto>
new SomeDto { Id = 1, Code = "T1", Name = "Test1", Description = "First" },
new SomeDto { Id = 2, Code = "T2", Name = "Test2", Description = "Second" },
new SomeDto { Id = 3, Code = "T3", Name = "Test3", Description = "Third" },
new SomeDto { Id = 3, Code = "T4", Name = "Test4", Description = "Forth" }
Data = OriginalData.Select(x => (SomeDto)x.Clone()).ToList();
private void ChangeData()
dto.Code = "F" + dto.Id.ToString();
private void RemoveUnchanged()
Data.RemoveAll(x => OriginalData.Any(y => y.Equals(x)));
public int Id { get; set;}
public string Code { get; set; }
public string Name { get; set; }
public string Description { get; set;}
return MemberwiseClone();
public override string ToString()
return "Id: " + Id + ", Code: " + Code + ", Name: " + Name + ", Description: " + Description;
public override bool Equals(object obj)
public bool Equals(SomeDto obj)
return obj.Id == Id && obj.Code == Code && obj.Name == Name && obj.Description == Description;