Click here to Skip to main content
15,909,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var _Col_Name_lst = (from DataColumn x in _hdr[0].Table.Columns
select x.ColumnName).ToArray();

_Col_Name_lst ----- This has a collection of string array

like

0 - EMl

1 - AZEER

2 - VISTA

--------

Here in above collection, i require array index of EMI or AZEER or VISTA whichever i pass to a linq.

so using linq on above collection --- "_Col_Name_lst "

i require index of any values EMI or AZEER or VISTA whichever i pass
Posted

try below code

C#
var index=0;
var _Col_Name_lst = (from DataColumn x in _hdr[0].Table.Columns
 select new {
      RowIndex = index++, 
      ColumnName = x.ColumnName}).ToArray();


In the new list RowIndex will contain the index of each column name.
 
Share this answer
 
C#
var result = _Col_Name_lst.Select((s, i) => new { Pos = i, text =s})
.Where(currentItem => currentItem.text.ToUpper()=="AZEER") //select matching item only
.Select(n=> n.Pos);// select only what you want, i.e. just position of item


Note: here result will just store index value of matching item
 
Share this answer
 
v3
Comments
here2learn.net 29-May-13 9:44am    
Thanks for formatting Tadit... :-)
I am still learning CP's posting interface...

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