Click here to Skip to main content
15,887,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 28-Jan-16 22:11pm
v2
Comments
John C Rayan 29-Jan-16 4:45am    
if only two values why should it be in array? can you explain the reason. it can be two variables.

1 solution

C#
class A
  {

      public string CSVName { get; set; }
      public string Name {get;set;}
      public string SchemaName  {get;set;}
      public bool PrimaryAttribute {get;set;}

  }


C#
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 ;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900