Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. class Program
  2.     {
  3.         class testClass
  4.         {
  5.             public int Id { get; set; }
  6.             public string Name { get; set; }
  7.         }
  8.  
  9.         static void Main(string[] args)
  10.         {
  11.  
  12.             var listOne = new List<testClass>();
  13.             var listTwo = new List<testClass>();
  14.            
  15.             listOne.Add(new testClass { Id = 1, Name = "Test1" });
  16.             listOne.Add(new testClass { Id = 2, Name = "Test2" });
  17.             listOne.Add(new testClass { Id = 3, Name = "Test3" });
  18.             listOne.Add(new testClass { Id = 4, Name = "Test4" });
  19.  
  20.             listTwo.Add(new testClass { Id = 1, Name = null });
  21.             listTwo.Add(new testClass { Id = 2, Name = null });
  22.             listTwo.Add(new testClass { Id = 3, Name = null });
  23.             listTwo.Add(new testClass { Id = 4, Name = null });
  24.  
  25.  
  26.             foreach (var item in listTwo)
  27.             {
  28.                 item.Name = listOne.FirstOrDefault(x => x.Id == item.Id)?.Name;
  29.             }
  30.  
  31.             Console.ReadKey();
  32.         }
  33.      
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement