Skip to content

Instantly share code, notes, and snippets.

@jesuslpm
Last active March 15, 2016 15:18
Show Gist options
  • Select an option

  • Save jesuslpm/512ddc1fecaef4644709 to your computer and use it in GitHub Desktop.

Select an option

Save jesuslpm/512ddc1fecaef4644709 to your computer and use it in GitHub Desktop.
Ayende csv user data
public class UserData
{
public int Id { get; set; }
public string Email { get; set; }
}
public class UserDataSearcher
{
private readonly Dictionary<string, List<int>> userIdsByEmail;
public UserDataSearcher(IEnumerable<UserData> usersData)
{
userIdsByEmail = new Dictionary<string, List<int>>(StringComparer.InvariantCultureIgnoreCase);
foreach (var userData in usersData)
{
List<int> userIdList;
if (! userIdsByEmail.TryGetValue(userData.Email, out userIdList))
{
userIdList = new List<int>();
userIdsByEmail.Add(userData.Email, userIdList);
}
userIdList.Add(userData.Id);
}
}
public IEnumerable<int> GetUserIdsByEmail(string email)
{
List<int> userIdList;
if (userIdsByEmail.TryGetValue(email, out userIdList))
{
return userIdList;
}
return Enumerable.Empty<int>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment