linq查询列表< string>并将列表值匹配到字符串数组 [英] linq to query list<string> and match list value to string array
问题描述
我有一个List< string> whicha包含如下数据
在第0个索引它有如下数据
{CSVName = Name,SchemaName = adx_name,PrimaryAttribute = true}
&在第一个索引它有如下数据
{CSVName = Value,SchemaName = adx_value,PrimaryAttribute =}
i有一个String []数组其中包含以下价值
在第0个索引
名称
在第1个索引
Value
现在我想写一个查询来匹配string []数组值和list< string>
并检查主属性列表< string>设置为true或者不是
如果是真的那么我需要将该行的模式名称分配给某个变量
例如
在我的例子之上
{CSVName = Name,SchemaName = adx_name,PrimaryAttribute = true}
primaryattribute为真
因此此行的schemaname值将分配给任何变量
string valueofschemaname = SchemaName.value
输出将是:
valueofschemaname = adx_name;
请ans
类 A
{
public string CSVName { get ; set ; }
public string 名称{ get ; set ;}
public string SchemaName { get ; set ;}
public bool PrimaryAttribute { get ; set ;}
}
string [] arr = new string [ 2 跨度>];
arr [ 0 ] = 名称 跨度>;
arr [ 1 ] = Value 跨度>;
列表< A> list = new 列表< A>();
string valueofschemaname = list.Where(li = > li.CSVName == arr [ 0 ]&& li.PrimaryAttribute == true )。First()。SchemaName;
I have one List<string> whicha contains data as follows
at 0 th index it has data as follows
{ CSVName = Name, SchemaName = adx_name, PrimaryAttribute = true }
& at first index it has data as follows
{ CSVName = Value, SchemaName = adx_value, PrimaryAttribute = }
i have one String[] array which contains following value
at 0th index
"Name"
At 1st index
"Value"
Now i want to write a query to match the string[] array values with list<string>
and to check if "Primary attribute" of list<string> is set to true or not
if it is true then i need to assign
schema name of that row to some variable
for example
in above my example
{ CSVName = Name, SchemaName = adx_name, PrimaryAttribute = true }
primaryattribute is true
so schemaname value of this row will be assign to any variable
string valueofschemaname=SchemaName.value
output will be :
valueofschemaname=adx_name ;
please ans
class A { public string CSVName { get; set; } public string Name {get;set;} public string SchemaName {get;set;} public bool PrimaryAttribute {get;set;} }
string[] arr = new string[2]; arr[0] = "Name"; arr[1] = "Value"; List<A> list = new List<A>(); string valueofschemaname = list.Where(li => li.CSVName == arr[0] && li.PrimaryAttribute == true).First().SchemaName ;
这篇关于linq查询列表< string>并将列表值匹配到字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!