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 495417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:35:29+00:00 2026-05-13T05:35:29+00:00

Consider the following code, where each key has an identical value: IDictionary<string, string> quarterbackDictionary

  • 0

Consider the following code, where each key has an identical value:

IDictionary<string, string> quarterbackDictionary = new Dictionary<string, string>();
quarterbackDictionary.Add("Manning", "Manning");
quarterbackDictionary.Add("Brady", "Brady");
quarterbackDictionary.Add("Rivers", "Rivers");

My question:

  • Can I remove the redundancy, so that I don’t have to repeat each
    string twice, similar to the
    following:
IDictionary<string, string> quarterbackDictionary = new Dictionary<string, string>();
quarterbackDictionary.Add("Manning");
quarterbackDictionary.Add("Brady");
quarterbackDictionary.Add("Rivers");

FYI:

  • I’m using a Dictionary because I want to throw on an attempt to insert a duplicate key.
  • A HashSet would not throw on an attempt to insert a duplicate key.
  • 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-05-13T05:35:29+00:00Added an answer on May 13, 2026 at 5:35 am

    Perhaps you could use an extension method

    public static class DictionaryExtensions
    {
        public static void Add(this Dictionary<string, string> dictionary,  
            string keyAndValue)
        {
            string value;
            if (dictionary.TryGetValue(keyAndValue, out value))
            {
                throw new Exception();
            }
    
            dictionary.Add(keyAndValue, keyAndValue);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the following code: private static BackgroundWorker bg = new BackgroundWorker(); static void Main(string[]
Consider the following code, in theory the click event should bind to each element
Consider the following base code: (function($) { $.fn.myPlugin = function(settings) { return this.each(function() {
Consider the following code, which simply calls a method on each member of a
Consider following code public class City { public string Name { get { return
consider the following code: if (matcher1.find()) { String str = line.substring(matcher1.start()+7,matcher1.end()-1); /*+7 and -1
consider the following code: string x=3F; //0011 1111 string y=3F; //0011 1111 string result=FFF;
Consider the following code : $dom = new DOMDocument(); $dom->loadXML($file); $xmlPath = new DOMXPath($dom);
Please consider following code: 1. uint16 a = 0x0001; if(a < 0x0002) { //

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.