First of all, β any object as a string β and β any-object.ToString () β are completely different things in terms of their respective context.
string str = any-object as string;
1) This will cause any object to look like a string type, and if any object is not flushed to a string, then this operator will return null without throwing an exception. 2) This is a compiler service.
3) This works very well for any type other than a string, for example: you can do it like any object like Employee, where Employee is the class defined in your library.
string str = any-object.ToString();
1) This will call ToString () of any object of type protection. Because System.Object defines the ToString () method, any class in the .NET framework has the ToString () method available for reinstallation. The programmer will override ToString () in an object class or structuring and write code that returns a suitable string representation of any object in accordance with the responsibility and role that an object plays.
2) Similar to how you can define an Employee and Over-ride ToString () method, which can return the string representation of an Employee object as "FIRSTNAME - LASTNAME, EMP-CDOE".
Please note that in this case, the programmer has control over ToString (), and he has nothing to do with casting or type conversion.
this. __curious_geek
source share