Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EnumerableLookupSample
- {
- private static readonly Dictionary<string, string> FullNamesDb =
- new Dictionary<string, string>
- {
- { "Bill Gates", "billg@microsoft.com" },
- { "Bill Clinton", "bill@hope.ar.us" },
- { "Michael Jackson", "mj@wonderland.org" }
- };
- private static readonly Dictionary<string, string> NickNamesDb =
- new Dictionary<string, string>
- {
- { "billy", "billg@microsoft.com" },
- { "slick willy", "bill@hope.ar.us" },
- { "jacko", "mj@wonderland.org" }
- };
- private static readonly Dictionary<string, string> PrefsDb =
- new Dictionary<string, string>
- {
- { "billg@microsoft.com", "HTML" },
- { "bill@hope.ar.us", "Plain" },
- { "mj@wonderland.org", "HTML" }
- };
- [Fact]
- public void DictionaryLookup()
- {
- Assert.Equal("HTML", LookUp("billy").First());
- Assert.Equal("HTML", LookUp("Bill Gates").First());
- Assert.Equal(0, LookUp("Steffen").Count());
- }
- private static IEnumerable<string> LookUp(string text)
- {
- return
- FullNamesDb.TryFind(text)
- .Concat(NickNamesDb.TryFind(text))
- .SelectMany(y => PrefsDb.TryFind(y));
- }
- }
Add Comment
Please, Sign In to add comment