Thursday, March 17, 2011

C# - When an Object isn't an Object

One of the problems that I've run into with C# is that it is a bit different than Java. For example, they claim that all of the types are objects int, In32, string, String, etc. BUT ...

Trying to do this:

Int32 a = null;

Results in an error:

Error 1 Cannot convert null to 'int' because it is a value type

However ...

Object obj = null;

Int32 a = (Int32) obj;

Does not.

??????

Just as an FYI to the makers of C# ... why not just make it so you can set an In32 to a null value ... this would make the behavior a bit more consistent, and consistent with languages such as Java.

1 comment: