A Join parancs használatával, két adathalmaz összekötése
Forráskód:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using System.Linq;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
List<Player> player = new List<Player>() {
new Player("Kenan Kodro", 33, 13,0),
new Player("Attila Fiola", 21,0,0),
new Player("Nelson Oliveira", 7 ,0,1),
new Player("Ingason",30,3,1),
new Player("Odegaard", 37,15,2),
new Player("Jorginho",14,0,2),
};
List<Team> teams = new List<Team> {
new Team(0,"Videoton"),
new Team(1,"PAOK"),
new Team(2,"Arsenal"),
};
var innerjoin = from p in player
join t in teams on p.Csapat equals t.Csap_azon
select new
{
Jatekos = p.Nev,
Csapata = t.Csap_nev,
ID = t.Csap_azon,
};
foreach (var item in innerjoin)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
internal class Player {
private string nev;
private int merkozes;
private int gol;
private int csapat;
public string Nev
{
get {
return this.nev;
}
set {
this.nev = value;
}
}
public int Merkozes
{
get
{
return this.merkozes;
}
set
{
this.merkozes = value;
}
}
public int Gol
{
get
{
return this.gol;
}
set
{
this.gol = value;
}
}
public int Csapat
{
get
{
return this.csapat;
}
set
{
this.csapat = value;
}
}
public Player(string nev, int merkozes, int gol,int csapat) {
this.Nev = nev;
this.Merkozes = merkozes;
this.Gol = gol;
this.Csapat = csapat;
}
}
internal class Team {
private int csap_azon;
private string csap_nev;
public int Csap_azon
{
get
{
return this.csap_azon;
}
set
{
this.csap_azon = value;
}
}
public string Csap_nev
{
get
{
return this.csap_nev;
}
set
{
this.csap_nev = value;
}
}
public Team(int csap_azon, string csap_nev)
{
this.Csap_azon = csap_azon;
this.Csap_nev = csap_nev;
}
}
}
Videó: