c# - Copy list1 property to list2 based oncondition -


I have a list with some properties:

  public class Class1 {public entry Id; The name of the public string; } List & lt; Class 1 & gt; List1 = GetSomeData ()  

After this step I have filled all the IDs in the list but names are empty. I have another list, where these values ​​are filled in such a way :

  Public Class Class2 {Public Ent ID; The name of the public string; } List & lt; Class 2 & gt; List2 = GetSomeData ()  

Therefore list2 has filled the ID and name - Ids are similar to list1, but of course, on the second index.

It is possible to fill out the property name based on the ID2 through Linux 2, with the name list1? I have tried to do something like that, but it does not work, I am able to get names or names of names only, but not in list 1.

  list1.Join (list2, l2 => l2.Id, l1 => l1 ID, (L1, L2) => {l1.Name = l2 .Name; return l1Name;});  

Or this - but there is a problem with the new segment, so I can not save it again in list 1.

  (from L1 in list1) join L1 in L2 in L2. Select ID equal to L. ID. New {l1.Name = l2.Name});  

Thanks for the help

You have workable , But keep in mind that calculators have been lazy-rated. Your code sets an unmuted sequence, but does not actually move through calculation - as a result the setters are never included.

One way to implement calculation is to add ToList () at the end of its statement:

  list1.Join (list2, l2 = & Gt; l2.Id, l1 = & gt; l1.Id, (l1, l2) => {l1.Name = l2.Name; return l1Name;}) .toList (); It seems counter-intuitive, but your approach is also an unorthodox - it seems that generally changing properties within the calculation such as blocks. I think it would be better (clear and safe, even a bit more literally) to set the property to iterator:  
  list1.Join (list2 , L2 => L. 2. ID, L1 => L. 1.ID, (L1, L2) => New {L1 = L1, L2 = L2}. Ollist () .First (x => {x L1.Name = x.l2.Name;});  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -