Hi,
You can access that property because the method returns an object of type
Type
that represents the exception type.
I'm going to be more specific:
ex
is an
Exception
, so you can access the
GetType()
method by calling
ex.GetType()
. That stamement is of type
System.Type
(
link) that represents the type
Exception
. That type also has some other methods/properties, so you can access them by using the dot operator as you previously did with
ex
. So you can write (I'll split it here using parenthesis for didactic purposes, but they are not necessary).
(ex.GetType()).Name
[1]: you get the instance of
System.Type
of the instance of the Exception object
ex
(see Richard MacCutchan's answer for more details about the
GetType()
method).
[2]: now you have an instance of an object of type
System.Type
(
actually it does not matter how you got it, now you can actually use it): access the Name property of that instance. So you get "System.Exception" (I believe) because you asked the System.Type of an Exception object and that Type's name is "Exception".
That's what your code says.
Hope this helps.