How to execute LINQ query for dictionary?

Viewed 1283

I've got dictionary which contains IDs as string and cities name also as string. I want to find city by it's name and return ID. There's my code:

public string GetIdByCityName(string name)
{
    if (Cities.ContainsValue(name))
    {
        return Cities
            .Select(x => x)
            .Where(v => v.Value == name)
            .Select(k => k.Key)
            .ToString();
    }
    else
    {
        return string.Empty;
    }
} 

Cities is of course my dictionary. I have a problem, because this code is not working. I tried to use debugger and I found what value has been returned from method:

System.Linq.Enumerable+WhereSelectEnumerableIterator 2[System.Collections.Generic.KeyValuePair 2[System.String,System.String],System.Boolean]

What am I doing wrong?

2 Answers
Related