How can i use linq to retrieve the index of a collection/array when in the example below, I know the Age, Year, and CatDesc. For example I want to do the Linq equivalent of
var cIndex = Select ? from cBudget where Age = 50 and Year = 2003 and CatDesc = "Housing"
Member
99 Points
275 Posts
How can i use linq to retrieve the index of a collection/array
Aug 01, 2013 06:43 PM|DonnieS|LINK
How can i use linq to retrieve the index of a collection/array when in the example below, I know the Age, Year, and CatDesc. For example I want to do the Linq equivalent of
var cIndex = Select ? from cBudget where Age = 50 and Year = 2003 and CatDesc = "Housing"
Thanks
DonnieS
Member
99 Points
275 Posts
Re: How can i use linq to retrieve the index of a collection/array
Aug 01, 2013 06:46 PM|DonnieS|LINK
Here is the collection in question.
All-Star
193993 Points
28027 Posts
Moderator
Re: How can i use linq to retrieve the index of a collection/array
Aug 02, 2013 12:26 AM|Mikesdotnetting|LINK
Why do you want the index of the item when you can get a reference to the item through a straightforward query?
But if you do want the index for some purpose, you have to write your own extension method to get that. See the accepted answer from Slaks here: http://stackoverflow.com/questions/2471588/how-to-get-index-using-linq
Member
99 Points
275 Posts
Re: How can i use linq to retrieve the index of a collection/array
Aug 02, 2013 12:31 AM|DonnieS|LINK
- I would use a crystal ball if it gives me the index - Thanks very much.
Member
99 Points
275 Posts
Re: How can i use linq to retrieve the index of a collection/array
Aug 02, 2013 12:43 AM|DonnieS|LINK
Actually, I want the index to make changes to the row that fits that query as in
budget[index].Amount = NewlyUpdatedAmount
All-Star
193993 Points
28027 Posts
Moderator
Re: How can i use linq to retrieve the index of a collection/array
Aug 02, 2013 03:32 AM|Mikesdotnetting|LINK
You would tyically do that like this: