Jump to content

Linq foreach

- - - - -

  • Please log in to reply
1 reply to this topic

#1
mayasmitha

mayasmitha

    Newbie

  • Members
  • PipPip
  • 13 posts
I have a array of string say:

String[] Fields=new String[]{RowField,RowField1}

In which I can use the below query to get the values by specifying the values is query i.e RowField and RowField1:

var Result = (
from x in _dataTable.AsEnumerable()
select new
{
Name = x.Field<object>(RowField),
Name1 = x.Field<object>(RowField1)
})
.Distinct();

But if suppose I have many values in the Array like:

String[] Fields= new String[]
{
RowField,
RowField1,
RowField2,
.......
RowField1000
};

How can I use the query here without specifying each of the rowfield in the query?
How can i iterate through the array items inside the LINQ?

#2
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 231 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
Result.Select(x => whatever your criteria).Distinct()




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users