public static List <Activity> getActivityTop5(string Type, string UserId) { ArrayList lst = database.getByParam("UserId", UserId, _tableName); Activity obj = new Activity(); List <Activity> retList = new List <Activity>(); int index = 0; foreach (Object _o in lst) { obj = ActivityBLL.getConvertedObject(_o); if (obj.Type == Type) { retList.Add(obj); index++; } if (index == 5) { break; } } return(retList); }