通过列表< T>提取项目. List< T> [英] Extracting Items over an List<T> of List<T>
本文介绍了通过列表< T>提取项目. List< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从List<T>
的List<T>
中检索记录,并寻求您的帮助.
I am trying to retrieve records from a List<T>
of List<T>
and seek your help in getting it.
我正在尝试获取overdues.Accounts.AccountId = 'JKB1'
处的项目,以及如何在下面的列表项上进行操作.
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();
accounts.Add(new OverdueSlabAccounts()
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "500"
});
accounts.Add(new OverdueSlabAccounts()
{
AccountId = "JKB2",
AccountName = "JKB2",
SalesCode = "JKB",
Value = "500"
});
overdues.Add(new OverdueModel()
{
Slab = "T3",
Value = 1000,
Percentage = 0,
Accounts = accounts
});
//For T4
accounts.Clear();
accounts.Add(new OverdueSlabAccounts()
{
AccountId = "JKB1",
AccountName = "JKB1",
SalesCode = "JKB",
Value = "1000"
});
overdues.Add(new OverdueModel()
{
Slab = "T4",
Value = 1000,
Percentage = 0,
Accounts = accounts
});
}
推荐答案
为此,您可以结合使用Where
和Any
:
You can use Where
and Any
in combination for this :
var result = overdues
.Where(overdue => overdue.Accounts
.Any(account => account.AccountId == "JKB1"));
这将过滤与任何帐户相关联的AccountId
JKB1
This will filter those overdues for which associated any Account has AccountId
JKB1
这篇关于通过列表< T>提取项目. List< T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文