Answered by:
linq to fetch index of string array

Question
-
User946151542 posted
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
var _Col_Name = from col in _Col_Name_lst
where col == ("EML_power")
select col.IndexOf("EML_power");Tuesday, May 21, 2013 4:55 AM
Answers
-
User-68639941 posted
hi, refer below code
int index = Array.IndexOf(_Col_Name_lst, "AZEER");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 21, 2013 5:04 AM -
User-1910946339 posted
Using IndexOf seems reasonable to me but if you really want a linq solution then try
int theIndex = _hdr[0].Table.Columns.Select((col, idx)=> new {idx, col.ColumnName}).Single(p=>p.ColumnName=="EMI").idx;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 21, 2013 7:21 PM
All replies
-
User-68639941 posted
hi, refer below code
int index = Array.IndexOf(_Col_Name_lst, "AZEER");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 21, 2013 5:04 AM -
User946151542 posted
using linq , i require to find index id
Tuesday, May 21, 2013 5:15 AM -
User-1910946339 posted
Using IndexOf seems reasonable to me but if you really want a linq solution then try
int theIndex = _hdr[0].Table.Columns.Select((col, idx)=> new {idx, col.ColumnName}).Single(p=>p.ColumnName=="EMI").idx;
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 21, 2013 7:21 PM