While writing a LINQ query i'm unable to find why the output of the query using into keyword is coming like.Please go through the code once and solve my problem.
class Person_1
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
class Pet
{
public string Name { get; set; }
public string Owner { get; set; }
}
static void GroupJoinMethod()
{
Person_1 magnus = new Person_1 { LastName = "Hedlund",FirstName = "Magnus" };
Person_1 terry = new Person_1 {LastName = "Adams", FirstName = "Terry" };
Person_1 charlotte = new Person_1 { LastName = "Weiss", FirstName = "Charlotte" };
Person_1 arlene = new Person_1 {LastName = "Huff", FirstName = "Arlene" };
Person_1 dummy = new Person_1 { LastName = "Williams", FirstName = "Magnus" };
Pet barley = new Pet { Name = "Barley",Owner="Terry"};//, Owner = terry };
Pet boots = new Pet { Name = "Boots",Owner="Terry"};//, Owner = terry };
Pet whiskers = new Pet { Name = "Whiskers",Owner="Charlotte"};//, Owner = charlotte };
Pet bluemoon = new Pet { Name = "Blue Moon",Owner="Terry"};//, Owner = terry };
Pet daisy = new Pet { Name = "Daisy",Owner="Magnus"};//, Owner = magnus };
List<Person_1> peoples = new List<Person_1> { magnus, terry, charlotte, arlene,dummy };
List<Pet> pets = new List<Pet> { barley, boots, whiskers, bluemoon, daisy };
Console.WriteLine("\n\nVia Select into\n\n");
var result2 = from people in peoples
join pet in pets
on people.LastName equals pet.Owner
into gj
select new { people.FirstName };
foreach (var str in result2)
{
Console.WriteLine(str.FirstName);
}
}
Output:
Via Select into
Magnus
Terry
Charlotte
Arlene
Magnus
Why the output is coming when my join condition is not correct.when i remove into there is no output. What's the impact of into keyword in this.Please help