Pulling and printing a random entry from a dictionary of a list of strings. C#.

Hi all. I have a dictionary of a list of strings. Each key can have more than 1 value associated with it. My problem is, when I use the following code to print out a random entry, I don’t get what I asked for:

59851-capture.png

void PullRandom() {
        System.Random rand = new System.Random();
        string word;
        word = dbCopy.ElementAt(rand.Next(0, dbCopy.Count)).Value.ToString();
        print(word);
    }

EDIT: After playing around with this a little bit, I got the following output with this code (and yes, the dictionary key is in Russian):

59852-newcapture.png

void PullRandom() {
        StringBuilder builder = new StringBuilder();
        System.Random rand = new System.Random();
        string word;
        word = dbCopy.ElementAt(rand.Next(0, dbCopy.Count)).ToString();
        builder = builder.Append(word);
        print(builder);
        
    }

This is fine, however. It looks like it wants to add the list of values following the key… I don’t need them combined like that and I don’t see where that is occurring if I am only grabbing the key.

So. What I don’t understand is:

  1. Why does ToString() not work in this
    case?
  2. How can I get this to print out the
    actual string instead of whatever
    else it is trying to do?
  3. How can I print out the value
    separately from the key instead of them being combined in the same
    line?

You can read about lists here:

and about a dictioanries here:

PS: You can add some null checks if you are not sure something like:

if (randomListValues == null) 
{
    print("randomListValues is null");
}

then you will find what element is null.