Fellow C# erper's,
Please bear with me for asking all sorts of basic questions. In another 2 to 3 weeks I should be up to speed on at least most of the fundamental concepts and will actually be developing code..
I am aware that, we can typecast from one type variable (either value type variable or reference type variable) to another type.
I have 2 questions about casting:
Question 1:
I am trying out the following example and I am getting this error "cannont convert type 'int' to 'string'
abc variable is a reference type variable (string) and x is a value type. why can't cast int value type to string type? doesn't (string) do the type casting?Code:int x = 5; string abc = "hello"; abc = (string)x;
Is there a list some where that lists all the possible type casts?
Question 2
suppose I have 2 derived classes. say "CommercialPilot" and "AirforcePilot" and both derive from a base class called "Pilot".
Can't I type cast one objects from one derived class to another without any issues? (I mean "commericialpilot" object to "airforcepilot" object)
thanks
nath




Reply With Quote