How to deal with repeated conflicts of anonymous type?

I am creating an anonymous type and I have conflicting field names.

The following code does not work, since i.Name and i.Target.Name have a property with the same name; "Name".

How do I get around this? Here is the code:

i => new { i.Name, i.Target.Name, i.EndDate, i.LastUpdated }; 
+7
c # anonymous-types
source share
2 answers

Name the anonymous fields as follows:

 new {Name = i.Name, targetName = i.Target.Name, ... }; 
+21
source share
  i => new { i.Name, TargetName = i.Target.Name, i.EndDate, i.LastUpdated }); 
+4
source share

All Articles