c# - Find the position of a List Item in a List based upon specifice criteria using LINQ -


this question has answer here:

something similar linq find in position object in list, except accepted answer evaluating @ object level.

say have

public interface ifoo{     string text {get;set;}     int number {get;set;} } 

and

public class foo : ifoo{     public string text {get;set;}     public int number {get;set;} } 

now have list collection of ifoo so:

public ilist<ifoo> foos; 

i want write method brings index(es) of foos based upon property value and/ or values (for example, text or number in case) can like:

var fooindexes = foos.getindexes( f => f.text == "foo" && f.number == 8 ); 

how write that?

you use like:

public static ienumerable<int> getindices<t>(this ienumerable<t> items, func<t, bool> predicate) {     return items.select( (item, index) => new { item = item, index = index })                      .where(p => predicate(p.item))                      .select(p => p.index); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -