G
Guest
I can do either:
string s = (string)someObject;
or
string s = someObject as string;
Then I can do:
int i = (int)someObject;
but I cannot do:
int i = someObject as int;
Why is there a difference? I thought the as keyword was just another way to
do a simple type cast? Or is there some benefit to using the as keyword which
leads to better performance over doing the traditional type cast, which value
types cannot take advantage of?
string s = (string)someObject;
or
string s = someObject as string;
Then I can do:
int i = (int)someObject;
but I cannot do:
int i = someObject as int;
Why is there a difference? I thought the as keyword was just another way to
do a simple type cast? Or is there some benefit to using the as keyword which
leads to better performance over doing the traditional type cast, which value
types cannot take advantage of?