Exclude files with a certain extension from list
string invalidExtension = (from p in new List<string> { ".dll", ".pdb", ".suo", ".docstates", ".ico", ".bmp", ".vs10x", ".vspscc", ".vssscc", ".vsp", ".scc", ".user", ".ctl", ".datasource", ".vsmdi", ".testsettings", ".trx", ".dat" } where p == files[i].Extension.ToLower() select p).FirstOrDefault(); if (string.IsNullOrEmpty(invalidExtension)) { //Means it has an invalid extension }