Friday, 17 December 2010

Find the index of a list item

It took me a while to find how to do this, but once I had, my eyes will be ever open to the beauty of Linq.

The following code was used in a problem I was working on from Programming Praxis and compares a specific charater to a list of strings

//where row is a List variable and char1 is a charater of interest
var row1 = rows.FindIndex(r => r.Contains(char1) == true)

In the problem above the character can only appear once in the collection.

No comments:

Post a Comment