How can I make this Dictionary TryGetValue code more readable?

Posted by mafutrct on Stack Overflow See other posts from Stack Overflow or by mafutrct
Published on 2010-06-10T13:20:29Z Indexed on 2010/06/10 13:32 UTC
Read the original article Hit count: 190

I'd like to test if an id was not yet known or, if it is known, if the associated value has changed. I'm currently using code similar to this, but it is hard to understand for those not familiar with the pattern. Can you think of a way to make it more readable while keeping it short in LOC?

string id;
string actual;
string stored;

if (!someDictionary.TryGetValue (id, out stored) || stored != actual) {
    // id not known yet or associated value changed.
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET