Created
April 26, 2016 14:54
-
-
Save hoganlong/fe39ecbeb2a72c471821e83d5c845649 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var myPets = new List<petInfo>(); | |
var yourpets = new List<petInfo>(); | |
myPets.Add(new petInfo("me", "dog","Rex")); | |
myPets.Add(new petInfo("me", "fish","Goldy")); | |
myPets.Add(new petInfo("me", "iguana","Spikey")); | |
yourpets.Add(new petInfo("you", "dog","Spot")); | |
yourpets.Add(new petInfo("you", "cat","Tigger")); | |
yourpets.Add(new petInfo("you", "bird","Polly")); | |
var result = myPets.Union(yourpets).Select(x => | |
{ | |
if (x.Owner == "me") | |
return new { PetType = x.PetType, MyOwnerName = x.Owner, MyPetName = x.PetName, YourOwnerName = "", YourPetName = ""}; | |
else | |
return new { PetType = x.PetType, MyOwnerName = "", MyPetName = "", YourOwnerName = x.Owner, YourPetName = x.PetName}; | |
}); | |
result.Dump(); | |
} | |
public class petInfo | |
{ | |
public string Owner; | |
public string PetType; | |
public string PetName; | |
public petInfo(string owner, string petType, string petName) | |
{ | |
Owner = owner; | |
PetType = petType; | |
PetName = petName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was written for LINQPad4 -- so that is why I have the Dump() call. Remove that line if you are not using LINQPad4