Use a search (for example, a dictionary) to increase the speed of checking a type name:
List<string> StringList; //Populated in previous code Dictionary<string,Type> assemblyTypes = RandomAssembly.GetTypes() .ToDictionary(t => t.Name, t => t); foreach (String name in StringList) { if (assemblyTypes.ContainsKey(name)) { //Do stuff. } } }
You should also check which of the two collections ( StringList or assemblyTypes ) is likely to be larger. Usually you want a larger one to be converted to lookup in order to reduce the number of iterations.
source share