What value are you trying to retrieve from the FilteredElementCollector? And based off of that answer, how are you initializing your FilteredElementCollector? There are many different ways of doing it. For example, you can initialize your FilteredElementCollector (FEC) to grab everything in a drawing (which could be A LOT!). However, if you're only looking for specific types of Elements, you can set your FEC to only pull those types. For further example, if you only want FamilyInstances, you can set up your FEC like this:
var fecFittings = new FilteredElementCollector(pDoc)
.OfClass(typeof(FamilyInstance))
.OfType<FamilyInstance>()
.ToList();
which will return a List<FamilyInstance>. Furthermore, if you only wanted to return specific types of FamilyInstance's you can use lambda expressions like this in your FEC:
var fecFittings = new FilteredElementCollector(m_pDoc)
.OfClass(typeof(FamilyInstance))
.Where(pElt =>
{
int lCatId = pElt.Category.Id.IntegerValue;
return lCatId == (int)BuiltInCategory.OST_PipeAccessory ||
lCatId == (int)BuiltInCategory.OST_PipeFitting ||
lCatId == (int)BuiltInCategory.OST_MechanicalEquipment;
})
.OfType<FamilyInstance>()
.ToList();
From there, you can simply iterate through your List<FamilyInstance> with a foreach loop to find the specific elements you want:
foreach (FamilyInstance pFam in fecFittings)
{
/*Do what we need with each Element*/
}
I do this A LOT with my plug-in and I have little to no lag time. Finding out the best way to utilize your FECs is what will make the world of difference. Also, try to use foreach loops whenever possible. It saves you from having to worry about "Index Out of Bounds" errors.
Hope that helps!!