Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ClassFoo
- {
- public string word;
- public float score;
- //... etc ...
- }
- List<ClassFoo> result = new List<ClassFoo>();
- foreach (ClassFoo cf in collection)
- {
- if (cf.word.StartsWith(query) || cf.word.EndsWith(query))
- result.Add(cf);
- }
- Dictionary<char, List<ClassFoo>> indexByFirstLetter;
- foreach (var cf in collection) {
- indexByFirstLetter[cf.bar[0]] = indexByFirstLetter[cf.bar[0]] ?? new List<ClassFoo>();
- indexByFirstLetter[cf.bar[0]].Add(cf);
- indexByFirstLetter[cf.bar[cf.bar.length - 1]] = indexByFirstLetter[cf.bar[cf.bar.Length - 1]] ?? new List<ClassFoo>();
- indexByFirstLetter[cf.bar[cf.bar.Length - 1]].Add(cf);
- }
- foreach (ClasssFoo cf in indexByFirstLetter[query[0]]) {
- if (cf.bar.StartsWith(query) || cf.bar.EndsWith(query))
- result.Add(cf);
- }
Add Comment
Please, Sign In to add comment