c# - Why can't I implicitly cast this object to a class reference -
can please explain why doesn't work?
myclass myclass1 = new myclass(); object obj = myclass1; myclass myclass2 = obj; <-- error
if obj "points" same block of memory of type myclass, why can not "point" myclass2 same block of memory on last line?
thanks help.
the type of myclass2 "myclass
". can assign value of type is, or derives from, myclass
. object
not , not derive myclass
, need cast.
if able implicitly, happen if did object not myclass
?
Comments
Post a Comment