0

multiple keys for one value in c# dictionary.I want to form one dictionary i tried with this code for form dictionary

 var dictionary = e.Args.Select(a => a.Split(new[] { '=' }, 2))
                    .GroupBy(a => a[0], a => a.Length == 2 ? a[1] : null)
                    .ToDictionary(g => g.Key, g => g.FirstOrDefault());

Then how can i form dictionary that have multiple key for one value using c#.

munisamy
  • 19
  • 2
  • 7

1 Answers1

0

Use a Lookup (.NET 3.5 and above) from MSDN

Lookup(Of TKey, TElement)

Represents a collection of keys each mapped to one or more values.

By the way, if all your keys are contiguous (ie 1, 2, 3, ...), use a simple array.


Referred from here and here

Community
  • 1
  • 1
Ramesh Rajendran
  • 32,579
  • 35
  • 130
  • 205