Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:31:01+00:00 2026-06-05T07:31:01+00:00

What structure involving Key and Value pair should be adopted when both Key and

  • 0

What structure involving Key and Value pair should be adopted when both Key and Value are repeated?

Scenario:
I am generating an anonymous type in WPF this way

var result = Enum.GetValues(typeof(Key)).Cast<Key>()
                 .Select(x => new {Key = x, Value = (int)x});

I tried converting it to Dictionary using

.ToDictionary(Key => Key, Value => (int)Value);

OR

.ToDictionary(Key => (int)Key, Value => Value);

But in both cases it gives exception that An item with the same key has already been added. which means keys are repeated in both cases.

Now what structure should be adopted in this scenario? Should i go for KeyValuepair<int, Key>[] or anything other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:31:02+00:00Added an answer on June 5, 2026 at 7:31 am

    Personally I’d just stick with a Dictionary<TKey, List<TValue>> but if you want a fancier interface you might want to write your own MultiMap wrapper class for that.

    Of course, in neither case can you use ToDictionary since that uses the existing unique-key dictionary internally but you can write your own ToMultiMap extension method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following nested structure involving type parameters and type members: trait B
The structure of the table testtable is id int primary key productid int attributeid
Table structure goes something like this: Table: Purchasers Columns: id | organization | city
my structure is like this: master page aspx(web form) ascx(user control) I have a
File structure: Code : <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Metnik EL Logo</title> </head>
I did the following algorithm involving a Binary Heap structure: Algorithm: heapMinimum(node) Input :
My structure is like this: <p>something</p> <br/> <br/> <p>ssddfgdfg</p> <br/> <br/> <p>dsdfsfsdfsdfsd</p> <br/> <br/>
My structure of database (domain, data and services) are the same as : This
Project structure is: /foo pom.xml /foo-war pom.xml /foo-ear pom.xml This is my parent pom.xml
Structure of my table : ID(int) | NUMBER(int) | CREATED_AT(date) If I have three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.