0

I have a List of IJapaneseDictionaryEntry objects which are described below. Inside this are IKanji objects.

public interface IJapaneseDictionaryEntry
{
    int Sequence { get; }
    IEnumerable<IKanji> Kanjis { get; }
    IEnumerable<IReading> Readings { get; }
    IEnumerable<ISense> Senses { get; }
}

Where each object contains a list of IKanji objects

public interface IKanji
{
    string Text { get; }
    IEnumerable<KanjiInformation> Informations { get; }
    IEnumerable<Priority> Priorities { get; }
}

List<IJapaneseDictionaryEntry> entries = dictionary.GetEntries().ToList();

Can someone show me how it's possible to get a list of all the Text values in the Kanjis lists?

In other words if there are two objects in entries and the first has a Kanjis list with three entries and the second a Kanjis list with two entries then what I would like to see is a list containing 5 rows of Kanji.Text Another way to explain it would be that I want to see a single list of every Kanji.Text in entries

1 Answer 1

4

You can use the SelectMany method to flatten multiple lists into a single list. In this case, you could do something like this:

var items = dictionary.GetEntries()
                      .SelectMany(x => x.Kanjis)
                      .Select(x => x.Text)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.