S
S
Sithis5622022-02-28 13:40:37
WPF
Sithis562, 2022-02-28 13:40:37

How to merge lists from two files?

There are two files, one is a list of clients, the other is a list of client accounts. There are also 2 ListViews, one list of clients, and the second one should display the client's accounts (there can be 2 of them), that is, when a client is selected from the first ListView, the second one should contain accounts of only this client. Also, the files contain the IDs of clients, by which you can find the accounts of this client in the second file.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-02-28
@Sithis562

It looks like you need something like this:

var clients = GetClients(); // Каким-то образом получили клиентов
var accounts = GetAccounts(); // Каким-то образом получили список счетов

var clientsWithAccounts = (
    from client in clients
    let accountsForClient = accounts.Where(account => account.ClientId == client.Id).ToArray() // Предполагаем, что у счёта есть какой-то идентификатор клиента, по которому его можно сопоставить. И что у одного клиента может быть несколько счетов
    select new { Client = client, Accounts = accountsForClient }).ToArray();

You can also do the same with SelectMany. And if each client always has exactly one account - through Join

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question