且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

linq查询列表< string>并将列表值匹配到字符串数组

更新时间:2022-10-19 18:56:33

  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 ;