Movsar Bekaev
Movsar Bekaev

Reputation: 908

C# LINQ multiple arrays to simple list of objects

I have an array of objects List<SlovnikWords>, here is the model:

class SlovnikWord
{
    public int Id { get; set; } = -1;
    public string Title { get; set; }
    public string Description { get; set; }
    public List<Word> Forms { get; set; }
    ...
}

And the model for Word is as follows

class Word
{
    public int Id { get; set; } = -1;
    public string Title { get; set; }
    public string Description { get; set; }
    ...
}

I need to create a list of all the Forms from all the original list of SlovnikWords, here's what I came up with:

var q = SlovnikData.Select(x => x.Forms);

This unfortunately creates an array of arrays, where as I only need one dimensional array of Forms without the outer one, i.e. a compound of x.Forms, please help.

Upvotes: 0

Views: 701

Answers (1)

Darren Ruane
Darren Ruane

Reputation: 2485

This should do it:

var q = SlovnikData.SelectMany(x => x.Forms);

Upvotes: 3

Related Questions