Wednesday, February 29, 2012

why is there explicit casting in c#

there are 2 basic places where this is needed - when the precision is being truncated in numeric value types
and to access the members of actual type ;for example, if a child object is referenced by a parent then to get to the childs method you would need
   
   ((Child1)parent1).message()

I believe that with a number (1).ToString() works because it is implicitly being casted to object

No comments:

Post a Comment