here it’s explained in a short and precise manner.
It would be Convert.ToString(d) or d…ToString() if the data type has that method.
I guess C# peculiarity to make python and noob programmers to bang their heads in the wall.
It’s actually helping you by making things easier to understand once you overcome the initial hurdle that you have to follow some ground rules. python makes things way more confusing in that respect.
Com interfaces work generic, you get an instance without a clue whats in there. But you know from reading the api documentation.
In order to work with it further you need to assign (cast) it to the right type, at least in a strong typed language like C#. Now putting the type in front of the type with braces, is a so called C cast. If it fails it throws, and if uncatched it will crash your application. In Python you can do the same mytype(myinstance) -> Python (mytype)myinstance -> C#. Don‘t know if that’s actually working the same way.
C# offers another way in casting by using the as operator, which does not throw but returns a null value instead. But working with null (None=>Python)values is problematic as well.
Strings are a special case, because any class or struct can override a ToString() method, which, if overwritten, determines the string conversion.
In order to convert value types to other value types there is a Convert class which does that. This is where C and C# differs. Value types are float, double , byte, char etc pp.
Casting is not necessarily a conversion, it mainly is used to assign a generic or base object the right type. It works if the memory footprint matches if not it throws. If you get a GeometryBase object, you can try to cast it to a Brep, it will do if the instance is of that type, but it will throw if its a Mesh object for instance.
This whole COM story is crazy, I get to a point that I can dir() some class, type and I get it’s attributes but when I try SomeType.SomeAttribute or SomeType.SomeMethod I get an error. It’s really frustrating because the error says there’s no such attribute.
At the end just to be completely sure I understand what you said: by Throws do you mean throws and exception? An Error?