# 通过列表<t>提取项目<t>[英] Extracting Items over an List＜T＞ of List＜T＞ ### 问题描述

```public class OverdueModel
{
public string Slab { get; set; }
public double Value { get; set; }
public double Percentage { get; set; }
public List<OverdueSlabAccounts> Accounts { get; set; }
}

public class OverdueSlabAccounts
{
public string AccountId { get; set; }
public string AccountName { get; set; }
public string SalesCode { get; set; }
public string Value { get; set; }
}

void Main(){
List<OverdueModel> overdues = new List<OverdueModel>();
List<OverdueSlabAccounts> accounts = new List<OverdueSlabAccounts>();

//For T3
accounts.Clear();
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "500"
});

{
AccountId = "JKB2",
AccountName = "JKB2",
SalesCode = "JKB",
Value = "500"
});

{
Slab = "T3",
Value = 1000,
Percentage = 0,
Accounts = accounts
});

//For T4
accounts.Clear();
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "1000"
});

{
Slab = "T4",
Value = 1000,
Percentage = 0,
Accounts = accounts
});

}
```

## 推荐答案

```var result = overdues
.Where(overdue => overdue.Accounts
.Any(account => account.AccountId == "JKB1"));
```

## 其他推荐答案

```var filteredList = overdues.Where(x=>x.Accounts.Any(c=>c.AccountId=="JKB1"));
```

• enumoser.where:参考
• >参考

## 其他推荐答案

``` var account = accounts.Find(x => x.AccountId.Contains("JKB1")));
```

```var account = accounts.Find(x => x.AccountId.Equals("JKB1")));
```

### 问题描述

I am trying to retrieve records from a List<T> of List<T> and seek your help in getting it.

I am trying to fetch items where overdues.Accounts.AccountId = 'JKB1' and how can i do it over the below List Items.

```public class OverdueModel
{
public string Slab { get; set; }
public double Value { get; set; }
public double Percentage { get; set; }
public List<OverdueSlabAccounts> Accounts { get; set; }
}

public class OverdueSlabAccounts
{
public string AccountId { get; set; }
public string AccountName { get; set; }
public string SalesCode { get; set; }
public string Value { get; set; }
}

void Main(){
List<OverdueModel> overdues = new List<OverdueModel>();
List<OverdueSlabAccounts> accounts = new List<OverdueSlabAccounts>();

//For T3
accounts.Clear();
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "500"
});

{
AccountId = "JKB2",
AccountName = "JKB2",
SalesCode = "JKB",
Value = "500"
});

{
Slab = "T3",
Value = 1000,
Percentage = 0,
Accounts = accounts
});

//For T4
accounts.Clear();
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "1000"
});

{
Slab = "T4",
Value = 1000,
Percentage = 0,
Accounts = accounts
});

}
```

## 推荐答案

You can use Where and Any in combination for this :

```var result = overdues
.Where(overdue => overdue.Accounts
.Any(account => account.AccountId == "JKB1"));
```

This will filter those overdues for which associated any Account has AccountId JKB1

## 其他推荐答案

You could use Linq for the purpose

```var filteredList = overdues.Where(x=>x.Accounts.Any(c=>c.AccountId=="JKB1"));
```

Output ## 其他推荐答案

You can try this:

``` var account = accounts.Find(x => x.AccountId.Contains("JKB1")));
```

or

```var account = accounts.Find(x => x.AccountId.Equals("JKB1")));
```

this will get you the specific account Id you are looking for.