It doesn't work:-
if(keyval.Value == "menu") // false
but this works:-
if(keyval.Value.ToString() == "menu") // true
what is the difference between these two.
why the first condition isn't working?
It doesn't work:-
if(keyval.Value == "menu") // false
but this works:-
if(keyval.Value.ToString() == "menu") // true
what is the difference between these two.
why the first condition isn't working?
Presumably, keyval.Value
has a type of object
. That means that instead of comparing the two strings by value, you are comparing them by reference - and it's perfectly valid for two strings with the same value to be a different instance.
The proper way to do the comparison would be
if((string)keyval.Value == "menu")
if the values are always strings. Or just avoid storing string
s as object
s :)