Skip to content

Instantly share code, notes, and snippets.

@hoganlong
Created April 26, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoganlong/fe39ecbeb2a72c471821e83d5c845649 to your computer and use it in GitHub Desktop.
Save hoganlong/fe39ecbeb2a72c471821e83d5c845649 to your computer and use it in GitHub Desktop.
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;
}
}
@hoganlong
Copy link
Author

This was written for LINQPad4 -- so that is why I have the Dump() call. Remove that line if you are not using LINQPad4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment