Hello,
I'm new here, also in programming. I have a question which i couldn't find an answer to. What does it mean when a type is written in brackets e.g. (string)e.Data.GetData(DataFormats.FileDrop)
is it something like Convert.ToString()?
Thank you.
Loading
VulpesPosted May 11, 2011, 10:59 AM
ZygisPosted May 11, 2011, 10:33 AM
VulpesPosted May 11, 2011, 10:24 AM
So, in your example, you're taking an expression which has a return type of object (but is really a string) and casting it to its string value.
This is similar to using the Convert.ToString(object) method. However, if the object is null, then the latter returns an empty string.
In contrast, when you use a cast you will get an exception **. There is however a form of cast (using the 'as' keyword) which doesn't throw an exception but returns null. So:
string s = (string)obj; // throws an exception if obj is null **
string t = obj as string; // doesn't throw an exception if obj is null
string u = Convert.ToString(obj); // doesn't throw an exception either
** WRONG - see my next post