With this:
if (args.Parameter == "ContactIntermediaryPage")
...in a NavigatedTo() event handler, Resharper tells me: "Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'"
So should I change it to one of the following, and, if so, which one:
if ((string)args.Parameter == "ContactIntermediaryPage")
if (args.Parameter.ToString() == "ContactIntermediaryPage")
if (args.Parameter.Equals("ContactIntermediaryPage"))
I would choose third one, making it also case insensitive (if this is suitable in your case)
if (args.Parameter.ToString().Equals(
"ContactIntermediaryPage",
StringComparsion.InvariantCultureIgnoreCase))
In other words, if you're comparing to a string
make left part of equation a string
, to make clear to a compiler and to a reader of your code, what you're going to do on that line.
the first one if args.Parameter is always a string. It saves an extra call.
otherwise the second one if, and only if, all possible strings are within your code. If so, I would define the strings as constants and reference them in one place if possible.
If neither of the above are true, then go for Tigran's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With