使用linq C#根据对象的innervariables值从列表创建子列表 [英] creating a sublist from a list based on object's innervariables value using linq c#
本文介绍了使用linq C#根据对象的innervariables值从列表创建子列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有对象list1的列表,我想从该列表中选择一个List< object>.用
说"obj"
obj.type ="1001"
请建议对此的Linq查询
I have list of object list1 ,from this list i want to select a List<object> say "obj" with
obj.type="1001"
Please suggest Linq query for this
推荐答案
我遇到了您的问题:
使用以下代码:
var
I got your problem:
Use the below code:
var
obj = new List<test>();
var res = obj.FirstOrDefault( x => x.Type = "1001");
if (res != null)
{
//Process result
}
首先,没有名称扩展名为"type
"的对象
这是我尽可能接近我认为您要询问的LINQ查询:
First of all there is no extension to object with the name "type
"
Here is the LINQ query as close as I can get to what I think you are asking:
var list1 = new List<object>();
list1.Add("Something");
var item = list1.FirstOrDefault(i => i.GetType().ToString() == "System.String");
Console.WriteLine(item.GetType());
Console.ReadLine();
这篇关于使用linq C#根据对象的innervariables值从列表创建子列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文