0
ToString() vs as String
What is the difference between .ToString() and as string
1 Réponse
+ 7
First, look at this :
string y = x as String;
If you have cast operators in this code, it will be ignored. Also, if x is not an instance of a string, y will become null. Meaning that no exceptions will be thrown during code runtime.
string y = x.ToString();
So you would use this instead if you have cast operators, etc. But sometimes if it can't convert x to a string, it may throw exceptions.