Have you looked at the Revit API getting started material at all?
https://thebuildingcoder.typepad.com/blog/about-the-author.html#2
Your question is answered there in full, and many others also.
Basically, all you need is a filtered element collector that specifies those pipe instances of interest to you and returns their count. Something like this:
int nPipes = new FilteredElementCollector(doc)
.OfClass(typeof(Pipe))
.GetElementCount();
For more information, please refer to The Building Coder topic group on filtered element collectors:
https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9