Using 'as' for value types...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In many occasions I found code like this (especially in Microsoft's code)

object obj1
num1 = 0
[...
if ((obj1 as short) != 0

num1 = ((short) obj1)


But when I try to do it I get an error on (obj1 as short) saying that "The as operator must be used with a reference type ('short' is a value type)

So how come it works for others but not for me

Thanx
 
Andrew,
In many occasions I found code like this (especially in Microsoft's code):

I don't think I've ever seen such code. Got any pointers to it?

But when I try to do it I get an error on (obj1 as short) saying that "The as operator must be used with a reference type ('short' is a value type)"

So how come it works for others but not for me?

It doesn't work. Are you sure you're not confusing it with

if (obj is short) ...



Mattias
 
Back
Top