I am a relative newbie to C# as most of my web development work has been in VB. In VB something like a DataRow Object or Session Object will implicitly cast to say a string. I can say:
If myDataRow("name") = "Fred" Then ...
I appreciate that in C# this casting must be explicit, so my question - all three of the lines below compile and work as expected. The ToString() will throw an exception if the session object is null so I guess that option is less 'good' as I would have to check for null first, but is one option more efficient or considered better C# coding practice than the others? Thanks a lot.
if ((string)Session["test"] == "abc") ...
if (Session["test"] as string == "abc") ...
if (Session["test"].ToString() == "abc") ...