c# - Joining two dictionaries -
hi have 2 dictionaries , need find way join them together.here 2 dictionary types.
idictionary<string, byte[]> dictionary1 idictionary<ifilesharedocument, string> dictionary2
out of 2 dictionaries have create third dictionary this
idictionary<ifilesharedocument, byte[]> dictionary3
both dictionaries have exact same number of items , string property of both them linking point.
what able write somethign this:
dictionary1.value join dictionary2.key dictionary1.key == dictionary2.value statement should result in dictionary3.
is there way can achieve can not seem find way this?
here's way using linq query syntax, join
(this compiles same thing @kingking's solution):
idictionary<ifilesharedocument, byte[]> dictionary3 = (from item1 in dictionary1 join item2 in dictionary2 on item1.key equals item2.value select new { item2.key, item1.value }) .todictionary(x => x.key, x => x.value);
note above preferred example using from
, where
, because more efficient. i'm including here because if you're me (more familiar sql, convert join automatically), poor way might first 1 comes mind:
idictionary<ifilesharedocument, byte[]> dictionary3 = (from item1 in dictionary1 item2 in dictionary2 item1.key == item2.value select new { item2.key, item1.value }) .todictionary(x => x.key, x => x.value);
Comments
Post a Comment