Getting the sum of random values from Dictionary

Hello all!

Coding C# question here!

I have inventory with 4 different objects: Lemon, Apple, Coffee, Mango

each object has different score: 20, 40, 60, 80 (respectively).

I want to use dictionary to assign the values. Dictionary<string, float> scoreDictionary = new Dictionary<string, float>()

Now whenever I see only apple, Lemon and Mango (or other combination), I want the method to sum their values

So my plane is to add each value to dictionary and then be able to sum the values based on the Key I get.

    if ((rows[0].stoppedSlot != rows[1].stoppedSlot) && (rows[1].stoppedSlot != rows[2].stoppedSlot))
    {
        for (int i = 0; i < prizeDictionary.Count; i++)
        {
            // here summarize the three values I get
        }
    }

So basically, in other script I assign a string and add it’s name + value to a dictionary,

and in the other script I want to say, “take the strings that you get” and sum the values based on the string name.

So I take it you want to add the values of the other three items. Something like this might work, feed the function a string name, the loop goes through each key and compares, adds to the score IF the key doesn’t match.

    int FindSum (string thisItem)
    {
        int totalScore = 0;
        foreach (string k in scoreDictionary.Keys)
        {
            if (k != thisItem)
            {
                totalScore += scoreDictionary[k];
            }
        }
        return totalScore;
    }