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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:59:09+00:00 2026-05-27T03:59:09+00:00

I was a homework, I had to implement some method. I can do the

  • 0

I was a homework, I had to implement some method. I can do the upload method, where I had to upload an dictionary in elements. If the Key had already in the Dictionary I had to update the Value. If the key wasn’t in the Dictionary, I had to add that element. In Foreach I could do that.

In the method never true in the if case, only the else case execute. ( In other way I tried to if(alcDictionary.Keys==alc) -but isn’t work). I don’t know why. Somebody can explain me where is my problem? Why never execute the If case. (Always write out “dont find”, and not the “find”)

I’ve written this method with containsKey():

     public void Upload(Alcohol alc, int dl)
    {
        int d = 0;
        Alcohol s = null;
        if (alcDictionary.ContainsKey(alc))
        {

            Console.WriteLine("I find");
            d = alcDictionary[alc];
            alcDictionary[alc] = d + dl;
        }
        else
        {
            Console.WriteLine("dont find");
            alcDictionary.Add(alc, dl);
        }

With Foreach ( It works good!)

            int d = 0;
        Alcohol s = null;
        foreach (var item in alcDictionary)
        {
            if (item.Key.Equals(alc))
            {
                d = item.Value;
                s = item.Key;
            }
        }
        if (s != null)
        {
            alcDictionary[s] = d + dl;
        }
        else
        {
            alcDictionary.Add(alc, dl);
        }

Some other code:

    public Kocsma()
    {
        Upload(new Alcohol("Borsodi alc", 160, 4.6), 1000);
        Upload(new Alcohol("Pilsner Urquell", 250, 4.4), 800);
        Upload(new Alcohol("Soproni Ászok", 150, 4.5), 900);
        Upload(new Alcohol("Dreher Classic", 200, 5.2), 600);
    }


    static void Main(String[] args)
    {
        Alcohol b = new Alcohol("Borsodi alc", 160, 4.6); //34
        Alcohol c = new Alcohol("Bratista alc", 230, 4.5); // 51
        Alcohol d = new Alcohol("Soproni Ászok", 150, 4.5); // 33,3

        Kocsma pub = new Kocsma();

        pub.Upload(c, 300);
        pub.Upload(d, 450);
        pub.Upload(b, 100);


    }
  • 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-27T03:59:09+00:00Added an answer on May 27, 2026 at 3:59 am

    You need to correctly override GetHashCode() in your key class.

    GetHashCode() must return equal values for equal objects.

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

Sidebar

Related Questions

Alright, i had this homework recently (don't worry, i've already done it, but in
Some background information, for a homework assignment I had to write a polish notation
I just had a homework assignment that wanted me to add all the Java
While doing some Java homework I answered a question by writing an instance method,
My kiddo had a homework assignment to write Blackjack in Java. I helped him
I'm doing some homework and while I have some experience with SML, Haskell has
I'm trying to implement user threads on a 2.4 Linux kernel (homework) and the
I need to implement quicksort in SML for a homework assignment, and I'm lost.
I'm stuck on part of my homework, I had to find the rightmost occurrence
Hey this is one of the classes that I had for homework in my

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.