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
?
What is the difference between Casting and Parsing?
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)
UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"] as String
is this Casting or parsing?
This is special kind of casting that will not fail if types aren't convertible (look here), but will get you null
.
(String) UserAdapter.GetIdAndUserTypeByEmailAndPassword(Email, Password).Rows[0]["UserType"]
is this Casting or parsing?
This again is casting, but will throw an exception if expression isn't of type string
.
What is the difference bewtween x.ToString() and (String) x?
x.ToString()
will try to call ToString() on the object x.
(String) x
will try to cast x to string, and will fail if x isn't string.
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