Search code examples
trellomanatee.trello

Find the index of Manatee.Trello.ListCollection by list name


I am try to find the index of a list returned by Manatee but i am unable to figure it out.

        var TrelloList = Trelloboard.Lists;
        var XML = Trelloboard.Lists[2].Cards[0].Description;
        Console.WriteLine(TrelloList.IndexOf("Swim Lane"));

Solution

  • The collections in Manatee.Trello all implement IEnumerable<T>. As such, all Linq operations will work on them.

    If you want to find your list:

    var swimLaneList = Trelloboard.Lists.FirstOrDefault(l => l.Name == "Swim Lane");
    

    If it's really the index of the list you're after, you can enumerate the collection to a List<T> and then use the .IndexOf() method as you have in your example.

    var lists = Trelloboard.Lists.ToList();
    var swimLaneList = lists.FirstOrDefault(l => l.Name == "Swim Lane");
    // don't forget to check for null
    var index = lists.IndexOf(swimLaneList);
    

    You might also want to read the wiki pages for more information on using this library.