因此,我无法在Group By目前为Linq打包头,本质上我正在寻找从Pirate和船内所有信息中获取ID,理想情况下抛出到IEnumerable DataRow(DataRow隐藏..)的列表中。Linq按列表从列表中进行分组
public class Pirate
{
public string Id { get; set; }
public List<Ship> Ships { get; set; }
}
public class Ship
{
public string Name { get; set; }
public string ShipClass { get; set; }
public string AvastyMast { get; set; }
}
static void Main(string[] args)
{
List<Pirate> Pirates = new List<Program.Pirate>();
Pirate Arr = new Pirate();
Arr.Id = "1";
Ship Pinta = new Ship();
Pinta.Name = "Maria";
Pinta.ShipClass = "BattleShip";
Pinta.AvastyMast = "You Sunk My BattleShip";
Ship Manta = new Ship();
Pinta.Name = "Clara";
Pinta.ShipClass = "Scout";
Pinta.AvastyMast = "You Sunk My BattleShip!";
Arr.Ships.Add(Pinta);
Arr.Ships.Add(Manta);
Pirates.Add(Arr);
Pirate Sid = new Pirate();
Sid.Id = "2";
Ship Nuclara = new Ship();
Pinta.Name = "Boon";
Pinta.ShipClass = "Sub";
Pinta.AvastyMast = "You Sunk My BattleShip!!";
Ship Nutella = new Ship();
Pinta.Name = "Slimer";
Pinta.ShipClass = "Scout";
Pinta.AvastyMast = "You Sunk My BattleShip!!!";
}
所以我想要做的就是从上面有通过LINQ的数据行的列表,所以如果我去通过每个DataRow的,并写了每一行和每一列,将产生以下。
1 , Maria, BattleShip, You Sunk My Battleship
1 , Clara, Scout, You Sunk My Battleship!
2 , Boon, Sub, You Sunk My Battleship!!
2, Slimer, Scout, You Sunk My Battleship!!!
你的问题不是很清楚。什么是输入和什么是预期输出? –
'从海盗和船舶内的所有信息中获取id,理想情况下扔进IEnumerable列表中。“什么? –
您的代码不能编译。 'class'是一个保留关键字。这些私人领域?或者他们应该是公共财产? –