I have been working on some code for a while. for now i have just used the keywords as-is without actually understanding them. So here is my question
What is the difference between Casting and Parsing?
UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"] as String–> is this Casting or parsing?
(String) UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"]
–>is this Casting or parsing?
UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"].ToString()
What is the difference bewtween x.ToString() and (String) x?
Those are unrelated.
Casting is changing the type of the variable.
Parsing is ‘examining’ the string and assigning its logical value to some variable.
(ADDITION: Well, they are related in a sense, because from far far away both can serve to ‘convert’ data, however, data is really converted ONLY in case of parsing)
This is special kind of casting that will not fail if types aren’t convertible (look here), but will get you
null.This again is casting, but will throw an exception if expression isn’t of type
string.x.ToString()will try to call ToString() on the object x.(String) xwill try to cast x to string, and will fail if x isn’t string.